小编ck_*_*jun的帖子

如何为同一个表指定多个连接的别名?

我的模型中有两个关系定义在同一个表中

public function getCountry(){
    return $this->hasOne(Country::className(),['country_id' => 'country_id']);
}

public function getCurrency(){
    return $this->hasOne(Country::className(), ['country_id' => 'currency']);
}
Run Code Online (Sandbox Code Playgroud)

我想在我的查询中加入这两个关系.下面的代码显示错误.

Country::find()->joinWith(['country','currency'])->....
Run Code Online (Sandbox Code Playgroud)

也试过这个

Country::find()->joinWith(['country','currency as cur'])->....
Run Code Online (Sandbox Code Playgroud)

如何为第二关系指定别名?

yii2

5
推荐指数
2
解决办法
5909
查看次数

Yii2动态URL路由规则

我想Dynamic Routing在yii2中的Cms页面中设置url.当我添加Cms页面时,我将添加页面别名aboutus,faq,management等,这些别名将保存在db中.

当我给URL规则静态时它会工作,[检查下面的代码]

'urlManager' => [               
            'showScriptName' => false,  
            'enablePrettyUrl' => true,  
            //'enableStrictParsing' => true,
            'rules'=>array(
'aboutus'=>'cms/index/1',
'faq'=>'cms/index/2',
'termacondition'=>'cms/index/3',
'management'=>'cms/index/4',
),
        ], 
Run Code Online (Sandbox Code Playgroud)

但我想动态添加网址规则.

我需要在yii2中的config/main.php URL规则中添加所有动态页面别名.请帮帮我.

php url-routing yii2

3
推荐指数
1
解决办法
2684
查看次数

标签 统计

yii2 ×2

php ×1

url-routing ×1