我的数据库中有 4 个表,每个表都包含 (id, name) 列。
型号:
表1 = id, 名称; 表2 = id, 名称;
我想为我的 GeneralController 中的每个表执行 1 个 actionIndex() 和 1 个 View 文件,但我不知道该怎么做。
public function actionIndex() {
$model = Table1::model()->findAll();
$this->render('index', array('model'=>$model);
}
也许可以在actionIndex($id)中发送参数来定义表和调用函数
if($id==1) {}
但也许我也会有 10-15 个带有(id,列)的表
最佳答案
您可以将多个变量传递给 View :
public function actionIndex() {
$model = Table1::model()->findAll();
$model2 = Table2::model()->findAll();
$this->render('index', array('model'=>$model,'model2'=>$model2);
}
关于php - Yii 一个 actionIndex() 用于数据库中的 4 个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20751830/