我的模型中有两个关系定义在同一个表中
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)
如何为第二关系指定别名?
我想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规则中添加所有动态页面别名.请帮帮我.