2016-10-29 24 views
2

美好的一天!我想把表格從聯繫表格轉到索引頁面。但是我不知道怎麼做。以下是接觸形式的代碼:呼叫其他表格在Yii2高級版中索引

/*create.php*/ 

<?php 
use yii\helpers\Html; 
$this->title = 'Create Contact Form'; 
$this->params['breadcrumbs'][] = ['label' => 'Contact Forms', 'url' => 
['index']]; 
$this->params['breadcrumbs'][] = $this->title;?> 
<div class="contact-form-create"> 
<h1><?= Html::encode($this->title) ?></h1> 
<?= $this->render('_form', ['model' => $model,]) ?> 
</div> 

/*_form.php*/ 

<?php 
use yii\helpers\Html; 
use yii\widgets\ActiveForm; ?> 

<div class="contact-form-form"> 
<?php $form = ActiveForm::begin(); ?> 
<?= $form->field($model, 'sender_name')->textInput(['maxlength' => true]) ?> 
<?= $form->field($model, 'sender_email')->textInput(['maxlength' => true]) ?> 
<?= $form->field($model, 'subject')->textInput(['maxlength' => true]) ?> 
<?= $form->field($model, 'content')->textarea(['rows' => 6]) ?> 

<div class="form-group"> 
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update' 
, ['class' => $model->isNewRecord ? 'btn btn-success' : ' 
btn btn-primary']) ?> 
</div> 

<?php ActiveForm::end(); ?> 
</div> 

回答

1

相反

<?= $this->render('_form', ['model' => $model,]) ?>

嘗試

<?= \Yii::$app->view->render('@frontend/views/contact-form/_form', ['model'=> $model) ?>

+0

您好!謝謝你的回覆。我試圖使用你給我的代碼,但它不起作用。也許我的問題不清楚。我想要做的就是將聯繫表單的表單放置在views \ site \ index.php中的主頁面上。 –

+0

您想要在索引內打印聯繫表單,對嗎?然後,您還應該澄清聯繫表單的查看路徑,以便我可以用該路徑編輯我的答案 –

+0

您是正確的。聯繫表單的視圖路徑是前端/視圖/聯繫表單。 contact-form文件夾包含以下php文件:_form,_search,create,index,update和view。 –