在我的情况下,我正在尝试执行slide(controller)/index(action)
并呈现相应的视图(index
)。它们都是这样的供应商文件夹:
vendor/
tomaivanovtomov/
yii2-revolution/
controllers/
models/
views/
slide/
index.php
我应该如何构建我的网址以便与他们联系?在此之前它只是www.example.com\backend\web\slide\index
。现在它给了我一个预期的错误,但我意识到我不知道如何联系他们。有没有办法,或者我应该至少在我的backend\controllers\
目录中覆盖控制器并调用它?先感谢您!
编辑现在我这样做了:
1. Override the `SlideController.php` to my `backend\controllers\` directroy
2. Extend the `vendor/tomaivanovtomov/revolution/controllers/SlideController.php`
3. In action index set the layout to `$this->layout = '@vendor/tomaivanovtomov/yii2-revolution/views/slide/index';`
4. And the return to `return $this->render('@vendor/tomaivanovtomov/yii2-revolution/views/slide/index', [
'dataProvider' => $dataProvider,
'hidden' => $hidden
]);`
这是我的slide/index
行动:
public function actionIndex()
{
$this->layout = '@vendor/tomaivanovtomov/yii2-revolution/views/slide/index';
$searchModel = new SlideSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$hidden = new Slide();
return $this->render('@vendor/tomaivanovtomov/yii2-revolution/views/slide/index', [
'dataProvider' => $dataProvider,
'hidden' => $hidden
]);
}
这样它可以正确呈现视图,但会发生错误Undefined variable: hidden
。任何sugestions为什么?谢谢!
的修改
索引文件:
<?php
use yii\widgets\ListView;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use backend\components\BackendPrefix;
\kartik\file\FileInputAsset::register($this);
/* @var $this yii\web\View */
/* @var $searchModel backend\models\SlideSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Slides');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<button type="button" class="btn btn-primary" onclick="addSlideModel('<?= BackendPrefix::PREFIX ?>')"><?= Yii::t('app', 'Add slide') ?></button>
</div>
</div>
<?php
$form = ActiveForm::begin([
'options' => [
'multipart/form-data'
],
'action' => [
'slide/create'
],
'id' => 'slides'
]);
//Hidden model to enable UploadFile class
echo $form->field($hidden, 'image[]')->fileInput(['class' => 'display-n'])->label(false);
echo ListView::widget([
'dataProvider' => $dataProvider,
'layout' => "{items}",
'itemView' => function( $model, $key, $index, $widget ){
return $this->render("_slideImage", [
'model' => $model,
'index' => $index
]);
},
]);
?>
<div class="col-sm-12">
<div class="form-group mt20">
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
</div>
</div>
<?php
ActiveForm::end();
?>
</div>