How can I customize yii2 theme

2019-02-04 22:17发布

Im just trying Yii2. Now I have created a yii2 basic appication. Next what I want to do is change the theme. I have an HTML file I want to change this appications theme as like that HTML. I have gone through yii2 theming But Its not what i want I want to add all css,js,images,font of that HTML to my project. How can I do this in yii2 Plz somebody help me.

标签: yii yii2
2条回答
来,给爷笑一个
2楼-- · 2019-02-04 22:57

Hi you have to do following things for theming in yii2 as simple as yii1 :-

  1. first of all open web.php into config directory of yii2 application,
  2. then in component array pass view array like:

        'view' => [
                  'theme' => [
                     'pathMap' => [ 
                        '@app/views' => [ 
                            '@webroot/themes/demo/views',
    
                         ]
                     ],
                   ],
                ] // here demo is your folder name
    

now create the folder name as "themes" into web directory.

In this themes folder copy your html folder like(demo) which contains all css, js etc. files. in this folder create views folder as yii which contains main.php and others layouts if needed.

override index.php in views by your corresponding index file by appropriate changes into paths of files. create corresponding views and actions for your html files. in yii2 we can define our css and js into Appasset.php .

查看更多
▲ chillily
3楼-- · 2019-02-04 23:04

Hi you need to do a few things to start off.

  1. Copy the new HTML template Css, JS, Plugins and Images into your project directory eg testdrive/assets/

  2. We need to link the CS and Js files to the project. Go to testdrive/protected/views/layouts/ directory and create a new file eg main.php add the respective css and js links to the respective files as you would on a html file in the head section.

    <head>
        <link href="<?php echo Yii::app()->request->baseUrl; ?>/assets/css/style.css" rel="stylesheet">
        <title><?php echo CHtml::encode($this->pageTitle); ?></title>
    </head>
    <body><? php echo $content ?></body>
    

3.Once the layout is ready we need to initialise yii to use the layout we have created. Proceed to the Controller eg SiteController.php

public function actionlogin{
   $this->layout = 'main';
}
  1. Now you're set to get your hands dirty.
查看更多
登录 后发表回答