Codeigniter整合smarty

2024-06-16 15:32
文章标签 整合 smarty codeigniter

本文主要是介绍Codeigniter整合smarty,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

smarty的模板机制很强大,一般情况下CI无需整合其他模板标签,因为PHP本身就是一种标签,简单易用。codeigniter整合smarty教程(我用的都是最新版本)如下:
第一步:下载codeigniter最新版本: http://codeigniter.org.cn/downloads
第二步:下载smarty最新版本: http://www.smarty.net/download
第三步:
配置步骤:
(1)将s marty拷贝到application/libraries下,然后再根目录下下新建templates,templates_c,config,cache目录,结构如下:


codeigniter轻松整合smarty



(2)入口文件新增:define('ROOT', dirname(__FILE__));
(3)libraries下新建CI_Smarty.php

  1. <?php defined('BASEPATH') or die('Access restricted!');
  2.  
  3. require(APPPATH . 'libraries/smarty/Smarty.class.php');
  4.  
  5. class CI_Smarty extends Smarty {
  6.  
  7. public function __construct($template_dir = '', $compile_dir = '', $config_dir = '', $cache_dir = '') {
  8. parent::__construct();
  9. if (is_array($template_dir)) {
  10. foreach ($template_dir as $key => $value) {
  11. $this->$key = $value;
  12. }
  13. } else {
  14. //ROOT是Codeigniter在入口文件index.php定义的本web应用的根目录
  15. $this->template_dir = $template_dir ? $template_dir : ROOT . '/templates';
  16. $this->compile_dir = $compile_dir ? $compile_dir : ROOT . '/templates_c';
  17. $this->config_dir = $config_dir ? $config_dir : ROOT . '/config';
  18. $this->cache_dir = $cache_dir ? $cache_dir : ROOT . '/cache';
  19. }
  20. }
  21.  
  22. }

controller中使用:
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. // by www.phpddt.com
  3. class Welcome extends CI_Controller {
  4.  
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->load->library('CI_Smarty');
  9. }
  10. public function test()
  11. {
  12. $this->ci_smarty->assign('test', 'smarty');
  13. $this->ci_smarty->display('test.tpl');
  14. }
  15. }
  16.  
  17. /* End of file welcome.php */
  18. /* Location: ./application/controllers/welcome.php */

这篇关于Codeigniter整合smarty的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1066829

相关文章

Spring Boot 整合 SSE(Server-Sent Events)实战案例(全网最全)

《SpringBoot整合SSE(Server-SentEvents)实战案例(全网最全)》本文通过实战案例讲解SpringBoot整合SSE技术,涵盖实现原理、代码配置、异常处理及前端交互,... 目录Spring Boot 整合 SSE(Server-Sent Events)1、简述SSE与其他技术的对

Java整合Protocol Buffers实现高效数据序列化实践

《Java整合ProtocolBuffers实现高效数据序列化实践》ProtocolBuffers是Google开发的一种语言中立、平台中立、可扩展的结构化数据序列化机制,类似于XML但更小、更快... 目录一、Protocol Buffers简介1.1 什么是Protocol Buffers1.2 Pro

springboot整合mqtt的步骤示例详解

《springboot整合mqtt的步骤示例详解》MQTT(MessageQueuingTelemetryTransport)是一种轻量级的消息传输协议,适用于物联网设备之间的通信,本文介绍Sprin... 目录1、引入依赖包2、yml配置3、创建配置4、自定义注解6、使用示例使用场景:mqtt可用于消息发

SpringBoot整合Dubbo+ZK注册失败的坑及解决

《SpringBoot整合Dubbo+ZK注册失败的坑及解决》使用Dubbo框架时,需在公共pom添加依赖,启动类加@EnableDubbo,实现类用@DubboService替代@Service,配... 目录1.先看下公共的pom(maven创建的pom工程)2.启动类上加@EnableDubbo3.实

SpringBoot整合(ES)ElasticSearch7.8实践

《SpringBoot整合(ES)ElasticSearch7.8实践》本文详细介绍了SpringBoot整合ElasticSearch7.8的教程,涵盖依赖添加、客户端初始化、索引创建与获取、批量插... 目录SpringBoot整合ElasticSearch7.8添加依赖初始化创建SpringBoot项

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red

Spring boot整合dubbo+zookeeper的详细过程

《Springboot整合dubbo+zookeeper的详细过程》本文讲解SpringBoot整合Dubbo与Zookeeper实现API、Provider、Consumer模式,包含依赖配置、... 目录Spring boot整合dubbo+zookeeper1.创建父工程2.父工程引入依赖3.创建ap

SpringBoot3.X 整合 MinIO 存储原生方案

《SpringBoot3.X整合MinIO存储原生方案》本文详细介绍了SpringBoot3.X整合MinIO的原生方案,从环境搭建到核心功能实现,涵盖了文件上传、下载、删除等常用操作,并补充了... 目录SpringBoot3.X整合MinIO存储原生方案:从环境搭建到实战开发一、前言:为什么选择MinI

SpringBoot整合liteflow的详细过程

《SpringBoot整合liteflow的详细过程》:本文主要介绍SpringBoot整合liteflow的详细过程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋...  liteflow 是什么? 能做什么?总之一句话:能帮你规范写代码逻辑 ,编排并解耦业务逻辑,代码

springboot整合TDengine全过程

《springboot整合TDengine全过程》:本文主要介绍springboot整合TDengine全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录环境准备JDBC-JNI方式准备依赖实体类Mapper配置类测试类RESTful方式实体类配置类测试类总结