Theming and layout in yii framework

前端 未结 2 861
南笙
南笙 2021-02-06 06:46

I am a newbie in Yii Framework and creating a CRM which is module based. Using different tutorials I am able to create my own theme, but now I am stucked at one point.

I

相关标签:
2条回答
  • 2021-02-06 06:50

    Try this step by step :

    1. Create New theme

      You can create a new theme and add this to the directory Application_Root/themes.

      Look at the themes/classic directory to get an an idea of the structure of the directory. The important file (at this stage) is :- Application_Root/themes/views/layouts/main.php

    2. Customise your theme contents

      Copy the css, image, js files etc to the correct directory and change the main.php file to your liking. For example, if your main.php says

      <link href="css/mystyle.css" rel="stylesheet">

      Then you will have a file Application_Root/css/mystyle.css

    3. Create the content placeholder.

      Somewhere in your main.php, there will be a placeholder for dynamic text, which is specified by.

      <?php echo $content; ?>

    4. Tell yii to use the theme. Change the file Application_Root/protected/config/main.php by adding the following line just before the last line (containing the closing bracket).

      'theme'=>'surveyhub'

    5. Create the layout placeholders.

      Create an HTML segment that will be written into the $contents portion of main.php. Call it for example one_column.php. The file path will therefore be Application_Root/themes/views/layouts/one_column.php In that file, where you want the dynamic text to be placed, create a placeholder.

      <?php echo $content; ?>

    6. Tell Yii to use the layout.

      In the file Application_Root/protected/components/Controller.php, add or modify the layout variable to read :

      public $layout='//layouts/one_column.php';

    7. Refresh the page

    0 讨论(0)
  • 2021-02-06 07:09

    Using a custom layout for your view is the right way to go. You can either set the layout in the controller action or in the view.

    $this->layout = "//layouts/mylayout";
    

    Note that the default layouts column1.php and column2.php also use the main.php layout file.

    0 讨论(0)
提交回复
热议问题