Witam, nie rozumiem frameworka yii2. Podstawa jest kontroler, jednak kazdy kontroller ma inny widok.
Robię sklep internetowy i wygląda to tak:
sitecontroller.php
<?php
namespace frontend\controllers;
use Yii;
use yii\data\Pagination;
use common\models\LoginForm;
use common\models\PostForm;
use common\models\SearchForm;
use common\models\User;
use common\models\UserFriend;
use common\models\UserYeswant;
use common\models\Post;
use common\models\ApiVideo;
use common\models\Material;
use common\models\PasswordResetRequestForm;
use common\models\ResetPasswordForm;
use common\models\SignupForm;
use common\models\ContactForm;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\web\UploadedFile;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\web\NotFoundHttpException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Site controller :)
*/
class SiteController extends \rootapp\components\Controllerrun
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post','get'],
],
],
'access' => [
'class' => AccessControl::className(),
'only' => ['index','myaccount'],
'rules' => [
[
'actions' => ['myaccount'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
if(!Yii::$app->user->isGuest){
return true;
}else{
return false;
}
}
],
[
'actions' => ['index'],
'allow' => true,
]
]
]
];
}
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
public function actionIndex()
{
$model = 'OK';
return $this->render('index',['model'=>$model]);
}
}
listcontroller.php
<?php
namespace app\Controllers;
class ListController extends \yii\web\Controller
{
public function actionIndex()
{
return $this->render('index');
}
}
Problem jest, że każdy kontroller ma inny widok z nagłówkami tzn. layouts a ja potrzebuje jednego layoutu i wiele /site
np. lista produktów, koszyk itp.
Czy do każdego powinno się tworzyć nowy kontroler?