Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 模块布局_Php_Layout_Yii_Module - Fatal编程技术网

Php 模块布局

Php 模块布局,php,layout,yii,module,Php,Layout,Yii,Module,我试图在模块中获得工作布局。所以我在模块的视图文件夹中创建了一个布局,名为 假设init()方法中的AdminModule.php中有一个布局。 现在看起来是这样的: public function init() { $this->layoutPath = Yii::getPathOfAlias('application.modules.admin.views.layouts'); $this->layout = 'adminLayout'; // this

我试图在模块中获得工作布局。所以我在模块的视图文件夹中创建了一个布局,名为

假设init()方法中的
AdminModule.php
中有一个布局。 现在看起来是这样的:

public function init()
{

    $this->layoutPath = Yii::getPathOfAlias('application.modules.admin.views.layouts');
    $this->layout = 'adminLayout';
    // this method is called when the module is being created
    // you may place code here to customize the module or the application

    // import the module-level models and components
    $this->setImport(array(
        'admin.models.*',
        'admin.components.*',
    ));


}
但由于某些原因,布局不适用于模块。我试着将“public$layout”添加到控制器中,它成功了

我想不出是什么问题


我还试图将布局设置添加到config文件夹中的
main.php
,但仍然没有任何操作。如果有人能提供帮助,我们将不胜感激。

解决方案已设置为模块中beforeControllerAction的布局。它应该会起作用

 public function beforeControllerAction($controller, $action)
  {
    if(parent::beforeControllerAction($controller, $action))
    {
      $controller->layout = 'adminLayout';
      return true;
    }
    else
      return false;
  }

解决方案是在模块中的beforeControllerAction上设置布局。它应该会起作用

 public function beforeControllerAction($controller, $action)
  {
    if(parent::beforeControllerAction($controller, $action))
    {
      $controller->layout = 'adminLayout';
      return true;
    }
    else
      return false;
  }

在模块中创建资产文件夹。为
assetsURL
添加以下代码:

private $_assetsUrl;

public function getAssetsUrl()
{
    if ($this->_assetsUrl === null)
        $this->_assetsUrl = Yii::app()->getAssetManager()->publish(
            Yii::getPathOfAlias('admin.assets') );
    return $this->_assetsUrl;
}
在ControllerAction函数之前创建一个
,并添加
$controller->layout

public function beforeControllerAction($controller, $action)
{
    if(parent::beforeControllerAction($controller, $action))
    {   
        // this overwrites everything in the controller
        $controller->layout = 'adminLayout';
        // this method is called before any module controller action is performed

        return true;
    }
    else
        return false;
}
导入所有
CSS
JS
文件,如:

<link rel="stylesheet" type="text/css" href="<?php echo $this->module->assetsUrl; ?>/css/style.default.css" media="screen, projection" />

在模块中创建资产文件夹。为
assetsURL
添加以下代码:

private $_assetsUrl;

public function getAssetsUrl()
{
    if ($this->_assetsUrl === null)
        $this->_assetsUrl = Yii::app()->getAssetManager()->publish(
            Yii::getPathOfAlias('admin.assets') );
    return $this->_assetsUrl;
}
在ControllerAction
函数之前创建一个
,并添加
$controller->layout

public function beforeControllerAction($controller, $action)
{
    if(parent::beforeControllerAction($controller, $action))
    {   
        // this overwrites everything in the controller
        $controller->layout = 'adminLayout';
        // this method is called before any module controller action is performed

        return true;
    }
    else
        return false;
}
导入所有
CSS
JS
文件,如:

<link rel="stylesheet" type="text/css" href="<?php echo $this->module->assetsUrl; ?>/css/style.default.css" media="screen, projection" />

关于这个主题有很多帖子,答案在Yii文档中:

布局属性

公共混合布局

此模块内控制器共享的布局如果控制器明确声明了自己的布局,则此属性将被忽略。如果此属性为null(默认值),则将使用应用程序的布局或父模块的布局(如果可用)。如果为false,则不会使用布局

只需从控制器中检测模块,并相应地设置布局:

class Controller extends CController
{

public function init(){

    //Set layout
    $this->layout = ($this->module->id=='admin') ? '//layouts/column2' : '//layouts/column1';
.........
}

关于这个问题有很多帖子,答案在Yii文档中:

布局属性

公共混合布局

此模块内控制器共享的布局如果控制器明确声明了自己的布局,则此属性将被忽略。如果此属性为null(默认值),则将使用应用程序的布局或父模块的布局(如果可用)。如果为false,则不会使用布局

只需从控制器中检测模块,并相应地设置布局:

class Controller extends CController
{

public function init(){

    //Set layout
    $this->layout = ($this->module->id=='admin') ? '//layouts/column2' : '//layouts/column1';
.........
}