💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
视图模板用的smarty3模板 并自定义模板定界符为:<{和}> (为了防止和jquery模板冲突) 这里仅对简单语法作介绍,更多语法请参考[smarty3中文手册](https://www.smarty.net/docs/zh_CN/) 视图目录为:Applications/webApp/view/控制器名(首字母大写其余字母小写)。 所有视图文件应统一放在视图目录下并以.html结尾。 控制器基类渲染函数为display($html,$data),其中$html为视图文件地址(相对于视图目录)。$data为传递变量数组。 示例:调用Applications/webApp/view/User/hello.html作为视图文件 ``` namespace controller; use workerWeb\web\Controller; class User extends Controller{ public function index (){ return $this->display('hello'); } } ``` 如果不传$html会以当前action的小写格式作为视图文件地址 如: ``` namespace controller; use workerWeb\web\Controller; class User extends Controller{ public function index (){ return $this->display(); } } ``` 会调用Applications/webApp/view/User/index.html作为视图文件。 $data必须传递数组格式,其作用为将php变量传递到视图文件中 如: ``` namespace controller; use workerWeb\web\Controller; class User extends Controller{ public function index (){ $name = 'word'; return $this->display('',['name'=>$name]); } } ``` 视图文件渲染变量方式为`<{$变量名}>` 如: ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> hello <{$name}>! </body> </html> ``` ![](https://box.kancloud.cn/bd36412126408921c3c67ba21d1c8032_398x164.png) 还有一种变量传递方式为调用控制器基类方法assign($name,$value); $name为传递参数名,$value为值。 调用示例: ``` //控制器文件 namespace controller; use workerWeb\web\Controller; class User extends Controller{ public function index (){ $name = 'word'; $this->assign('name',$name); return $this->display(); } } ``` 更多语法请参考[smarty3中文手册](https://www.smarty.net/docs/zh_CN/)