首页 > 代码库 > mac下yii2安装Smarty模板

mac下yii2安装Smarty模板

在项目根目录输入命令: php composer.phar require --prefer-dist yiisoft/yii2-smarty

如果报错 Could not open input file: composer.phar 则重新输入命令:omposer  require --prefer-dist yiisoft/yii2-smarty

技术分享

config下web.php的components里进行配置:

        ‘view‘ => [

            ‘renderers‘ => [

                ‘tpl‘ => [

                    ‘class‘ => ‘yii/smarty/ViewRenderer‘,

                //‘cachePath‘ => ‘@runtime/Smarty/cache‘,  

                ],

            ],

        ],

控制器 controller.php:

public function actionIndex(){       

        return $this->renderPartial(‘index‘, [‘text‘ => ‘ world!‘]);  

 }

模板 index.php:

hello{$text}

会输出:hello world!

mac下yii2安装Smarty模板