Yii 如何将变量从actionCreate传递到_form.php?
我有一个创建控制器的操作,我在其中将$Components数组传递到视图中Yii 如何将变量从actionCreate传递到_form.php?,yii,yii2,Yii,Yii2,我有一个创建控制器的操作,我在其中将$Components数组传递到视图中 public function actionCreate() { return $this->render('create', ['model' => $model, 'ingredients' => Ingredient::find()->all()] ); } 在create.php中,我可以访问$contracents变量。 但是如果我试图在_form.p
public function actionCreate()
{
return $this->render('create',
['model' => $model, 'ingredients' => Ingredient::find()->all()]
);
}
在create.php中,我可以访问$contracents变量。
但是如果我试图在_form.php中访问$contracents
<?= $form->field($model, 'ingredient_id')->checkbox(
ArrayHelper::map($ingredients, 'id', 'name')
) ?>
您正在将变量传递到
create
视图,您的小部件位于另一个名为\u form
的视图中。转到创建
视图,确保所有变量都传递到\u表单
视图。您正在将变量传递到创建
视图,并且您的小部件位于另一个名为\u表单
的视图中。转到创建
视图,确保所有变量都传递到表单
视图。这可以通过两种方式完成//首先像这样渲染视图文件
$params = [];
$params['eqpType'] = $eqpType;
$params['discountModel'] = $discountModel;
$params['tabActive'] = $tabActive;
$params['discountLabel'] = $discountLabel;
echo $this->render('_form', $params);
//或者您可以直接包含代码文件。在这种情况下,不需要通过所有参数
<?php include_once "_form.php";?>
这可以通过两种方式实现
//首先像这样渲染视图文件
$params = [];
$params['eqpType'] = $eqpType;
$params['discountModel'] = $discountModel;
$params['tabActive'] = $tabActive;
$params['discountLabel'] = $discountLabel;
echo $this->render('_form', $params);
//或者您可以直接包含代码文件。在这种情况下,不需要通过所有参数
<?php include_once "_form.php";?>
在create.php中
<?php echo $this->render('_form', [
'model' => $model,
'ingredients' => $ingredients
]) ?>
在create.php中
<?php echo $this->render('_form', [
'model' => $model,
'ingredients' => $ingredients
]) ?>
第一种方法帮助以及如果复选框名称为菜肴[配料][]
,我如何在控制器中获取一组复选框?第一种方法帮助以及如果复选框名称为菜肴[配料][]
,我如何在控制器中获取一组复选框?