我正在yii2中的一个项目中。我需要在input field
页面上放置一个index
。该字段应类似于表单字段。即创建记录时表单中使用的字段的类型。为此,我已完成以下操作
public function actionIndex()
{
$model = MdcmetercustRel::className();// this is the class whose data field I want to get
$searchModel = new MdcmetersdataSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model' => $model,
]);
}
我的索引
<?=
$form = ActiveForm::begin();
$relModel=$model->getModels()[0]; print_r($relModel['cust_id']);
$form->field($relModel, 'cust_id')->textInput()
?>
刷新页面时,我会得到
类yii \ widgets \ ActiveForm的对象无法转换为字符串
我该如何实现?
任何帮助将不胜感激
您的错误是<?=
,它正在尝试输出整个脚本,而您无法回显$form
或ActiveForm::begin()
将其更改为
<?php
$form = ActiveForm::begin();
$relModel=$model->getModels()[0]; print_r($relModel['cust_id']);
echo $form->field($relModel, 'cust_id')->textInput()
?>