CodeIgniter集成smarty的方法详解
框架(架构)  /  管理员 发布于 7年前   158
本文实例讲述了CodeIgniter集成smarty的方法。分享给大家供大家参考,具体步骤如下: 1.下载smarty 解压到ci的libraries目录 如: ci/application/libraries/Smarty-2.6.20 2.编写Mysmarty.php 自己的类库文件 代码如下: 3.在autoload.php让ci自动加载smarty 或者 使用模板时再自己加载smarty 4.smarty变量赋值 display模板 注:images css 等外部资源文件 放在ci系统文件夹外 网站根目录下 最好用: base_url()来访问: 不要放到system里 补充:小编在这里推荐一款本站的php格式化美化的排版工具帮助大家在以后的PHP程序设计中进行代码排版: php代码在线格式化美化工具: http://tools..net.cn/code/phpformat 另外,由于php属于C语言风格,因此下面这款工具同样可以实现php代码的格式化: C语言风格/HTML/CSS/json代码格式化美化工具: 更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《Zend FrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》 希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。Smarty(); $config =& get_config(); // absolute path prevents "template not found" errors $this->template_dir = (!empty($config['smarty_template_dir']) ? $config['smarty_template_dir'] : BASEPATH . 'application/views/'); $this->compile_dir = (!empty($config['smarty_compile_dir']) ? $config['smarty_compile_dir'] : BASEPATH . 'cache/'); //use CI's cache folder if (function_exists('site_url')) { // URL helper required $this->assign("site_url", site_url()); // so we can get the full path to CI easily } } /** * @param $resource_name string * @param $params array holds params that will be passed to the template * @desc loads the template */ function view($resource_name, $params = array()) { if (strpos($resource_name, '.') === false) { $resource_name .= '.html'; } if (is_array($params) && count($params)) { foreach ($params as $key => $value) { $this->assign($key, $value); } } // check if the template file exists. if (!is_file($this->template_dir . $resource_name)) { show_error("template: [$resource_name] cannot be found."); } return parent::display($resource_name); }} // END class smarty_library?>
$autoload['libraries'] = array('database', 'mysmarty');
$this->load->library("mysmarty");
$this->mysmarty->assign('test', 'Hello World.');$this->mysmarty->view('smarty');
$this->load->helper('url');
base_url()."images/xxx.jpg"
http://tools..net.cn/code/ccode_html_css_json您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号