php - Yii2 Theme Installation -
i trying install cerulean theme yii2 advanced template on frontend app. in main.php appasset::register($this); not including files. following code in appasset
<?php /** * @link http://www.yiiframework.com/ * @copyright copyright (c) 2008 yii software llc * @license http://www.yiiframework.com/license/ */ namespace frontend\assets; use yii\web\assetbundle; /** * @author qiang xue <qiang.xue@gmail.com> * @since 2.0 */ class appasset extends assetbundle { public $basepath = '@webroot'; public $baseurl = '@web'; public $css = [ 'css/site.css', 'css/site.css', ]; public $js = [ '/js/jquery.js', ]; public $depends = [ 'yii\web\yiiasset', 'yii\bootstrap\bootstrapasset', ]; }
and in main.php
<?php use yii\helpers\html; use yii\helpers\url; use yii\bootstrap\nav; use yii\bootstrap\navbar; use yii\widgets\breadcrumbs; use frontend\assets\appasset; use frontend\widgets\alert; use yii\bootstrap\activeform; /* @var $this \yii\web\view */ /* @var $content string */ appasset::register($this); ?> <?php $this->beginpage() ?> <!doctype html> <html lang="en"> <head> <meta charset="<?= yii::$app->charset ?>"/> <meta name="viewport" content="width=device-width, initial-scale=1"> <?= html::csrfmetatags() ?> <title><?= html::encode($this->title) ?></title> <?php $this->head() ?> <!-- le javascript ================================================== --> <!-- placed @ end of document pages load faster --> <script src="/themes/cerulian/js/jquery.js"></script> <script src="/themes/cerulian/js/bootstrap-transition.js"></script> <script src="/themes/cerulian/js/bootstrap-alert.js"></script> <script src="/themes/cerulian/js/bootstrap-modal.js"></script> <script src="/themes/cerulian/js/bootstrap-dropdown.js"></script> <script src="/themes/cerulian/js/bootstrap-scrollspy.js"></script> <script src="/themes/cerulian/js/bootstrap-tab.js"></script> <script src="/themes/cerulian/js/bootstrap-tooltip.js"></script> <script src="/themes/cerulian/js/bootstrap-popover.js"></script> <script src="/themes/cerulian/js/bootstrap-button.js"></script> <script src="/themes/cerulian/js/bootstrap-collapse.js"></script> <script src="/themes/cerulian/js/bootstrap-carousel.js"></script> <script src="/themes/cerulian/js/bootstrap-typeahead.js"></script> <!-- le styles --> <!-- <link href="/themes/cerulian/bootstrap/dist/css/bootstrap.css" rel="stylesheet">--> <link href="/themes/cerulian/css/bootstrap.css" rel="stylesheet"> <link rel="stylesheet" href="/css/site.css"> <style type="text/css"> </style> <link href="/css/developers.css"> <!-- html5 shim, ie6-8 support of html5 elements --> <!--[if lt ie 9]> <script src="js/html5shiv.js"></script> <![endif]--> <!-- fav , touch icons --> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/ico/apple-touch-icon-144-precomposed.png"> <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/ico/apple-touch-icon-114-precomposed.png"> <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/ico/apple-touch-icon-72-precomposed.png"> <link rel="apple-touch-icon-precomposed" href="/ico/apple-touch-icon-57-precomposed.png"> <link rel="shortcut icon" href="/ico/favicon.png"> <style> </style> <link rel="stylesheet" href="/css/developers.css"> </head> <body> <?php // echo '<pre>'; // print_r($this);exit; $this->beginbody() ?> </html>
see have added script , css file manually giving script , css tags.
in frontend/config/main.php following settings
'components' => [ // 'myhtmlelementsgenerator' => [ // 'class' => 'componentsmodels\user', // 'enableautologin' => true, // ], 'view' => [ 'theme' => [ 'basepath' => '@app/themes/cerulian', 'baseurl' => '@web/themes/cerulian', 'pathmap' => [ '@app/views' => '@app/themes/cerulian', ], ], ], 'log' => [ 'tracelevel' => yii_debug ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\filetarget', 'levels' => ['error', 'warning'], ], ], ], 'errorhandler' => [ 'erroraction' => 'site/error',![enter image description here][1] ], ],
following directory structure.
!http://i.stack.imgur.com/zckrk.png
issue assets register not working. in views cannot use $this->registerjs , $this->registercssfile. these functions not seems working. issue can 1 me? want include required files js/css in theme automatically added.
here how integrate yii2 advanced application custom theme, specially frontend. follow step, more info check out in youtube: https://www.youtube.com/watch?v=aubmpjdauq0
step 1 - download theme, sample using "carlote" theme. step 2 - extract custom theme vendor/bower. step 3 - edit view/layout.
copy index carlote theme main copy index.html beginning <body>..</body> add script top <?php use frontend\assets\appasset; use yii\helpers\html; /* @var $this \yii\web\view */ /* @var $content string */ $asset = frontend\assets\appasset::register($this); $baseurl = $asset->baseurl; ?>
step 4 - edit asset bundle in frontendfollow css/js or images carlote index.html
class appasset extends assetbundle { //public $basepath = '@webroot'; //public $baseurl = '@web'; public $sourcepath = '@bower/corlate/'; public $css = [ 'css/bootstrap.min.css', 'css/font-awesome.min.css', 'css/animate.min.css', 'css/prettyphoto.css', 'css/main.css', 'css/responsive.css', ]; public $js = [ 'js/jquery.js', 'js/bootstrap.min.js', 'js/jquery.prettyphoto.js', 'js/jquery.isotope.min.js', 'js/main.js', 'js/wow.min.js', ]; public $depends = [ 'yii\web\yiiasset', 'yii\bootstrap\bootstrapasset', ]; }
refresh frontend page,... done :)
Comments
Post a Comment