在项目根目录输入命令: 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!
时间: 2024-11-06 15:17:51