CI框架整合smarty步骤详解_php实例
本文详细讲述了CI框架整合smarty步骤。分享给大家供大家参考,具体如下:
Ci结合smarty的配置步骤:
1. 第一步配置ci和下载smarty的模板个人喜欢用(Smarty-3.1.8)这个版本。
2. 第二部把下载到的smarty版本解压然后把里面的libs文件改名为smarty然后把这个文件拷到ci\application\libraries目录下面
3. 在ci\application\libraries这个目录下面建立一个文件,文件名可以自定义,例如见一个tp.php的文档。
4. 用编译器打开tp.php然后写入以下代码:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once('smarty/smarty.class.php'); class Tp extends Smarty{ function tp(){ parent::Smarty(); $this->template_dir = APPPATH.'views'; $this->compile_dir = APPPATH.'templates_c/'; $this->left_delimiter = '<{'; $this->right_delimiter = '}>'; } }
5. 在建立一个ci\application\templates_c文件夹
6. 打开ci\application\config\autoload.php文件把
$autoload['libraries'] = array();
改成:
$autoload['libraries'] = array('database','tp');
OK我们的配置到这里就已经成功了,接下来我们开始测试
测试的第一步先建立一个控制器:
1. 在\application\controllers下建立一个文件名为ceshi.php的文件,文件内容
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Home extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper('url'); $this->tp->assign('base_url', base_url()); //定义css以及js的路径 } function index() { $this->tp->assign("title","恭喜你smarty安装成功!"); $this->tp->assign("body","欢迎使用smarty模板引擎"); $arr = array(1=>'zhang',2=>'xing',3=>'wang'); $this->tp->assign("myarray",$arr); $this->tp->display('ceshi.html'); } }
2.建立模板文件在ci\application\views目录下建立文件名为ceshi.html的文件,文件内容为
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src='<!--{$base_url}-->js/jQuery.min.js' type='text/JavaScript' ></script> <link href="<!--{$base_url}-->css/login.css" rel="stylesheet" type="text/css" /> <title>smarty安装测试</title> </head> <body> <h1><{$title}></h1> <p><{$body}></p> <ul> <{foreach from=$myarray item=v}> <li><{$v}></li> <{/foreach}> </ul> </body> </html>
最后输入地址http://localhost/ci/application/index.php/ceshi (主意ci代表的是你自己放置ci框架中文件的根目录)运行以后你将会看到你配置smarty成功的页面,到这里ci和smarty的整合以及测试就完工了
更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《smarty模板入门基础教程》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《Zend FrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the development of network technology, PHP has become one of the important tools for Web development. One of the popular PHP frameworks - CodeIgniter (hereinafter referred to as CI) has also received more and more attention and use. Today, we will take a look at how to use the CI framework. 1. Install the CI framework First, we need to download the CI framework and install it. Download the latest version of the CI framework compressed package from CI's official website (https://codeigniter.com/). After the download is complete, unzip

With the development of the Internet, big data analysis and real-time information processing have become an important need for enterprises. In order to meet such needs, traditional relational databases no longer meet the needs of business and technology development. Instead, using NoSQL databases has become an important option. In this article, we will discuss the use of SpringBoot integrated with NoSQL databases to enable the development and deployment of modern applications. What is a NoSQL database? NoSQL is notonlySQL

PHP is a popular programming language that is widely used in web development. The CI (CodeIgniter) framework is one of the most popular frameworks in PHP. It provides a complete set of ready-made tools and function libraries, as well as some popular design patterns, allowing developers to develop Web applications more efficiently. This article will introduce the basic steps and methods of developing PHP applications using the CI framework. Understand the basic concepts and structures of the CI framework. Before using the CI framework, we need to understand some basic concepts and structures. Down

UniApp realizes the perfect integration of the Vue.js framework Introduction: UniApp is a cross-platform development tool based on the Vue.js framework. It can compile a Vue.js project into applications for multiple different platforms, such as iOS, Android, small Programs etc. The advantage of UniApp is that it allows developers to write only one set of code and adapt to multiple platforms at the same time, speeding up development efficiency and reducing development costs. The following will introduce how to use UniApp to achieve perfect integration of the Vue.js framework

PHP is a widely used server-side scripting language, and CodeIgniter4 (CI4) is a popular PHP framework that provides a fast and excellent way to build web applications. In this article, we will get you started using the CI4 framework to develop outstanding web applications by walking you through how to use it. 1. Download and install CI4 First, you need to download it from the official website (https://codeigniter.com/downloa

Changes in Vue3 compared to Vue2: More powerful network request library integration As Vue.js continues to develop and update, Vue3, as the next version of Vue.js, brings some exciting changes and improvements. One of the most significant changes is more powerful network request library integration. In Vue2, we usually use third-party libraries such as axios to make network requests. In Vue3, the Vue development team has provided a built-in network request library, which provides us with a more intuitive and flexible method.

Practical tips for integrating PHPcms with other systems With the continuous development of Internet technology, the field of website development has become more diverse and complex. In actual projects, we often face situations where different systems need to be integrated, which requires us to have certain skills and experience to solve these problems. This article will introduce some practical tips and specific code examples for the integration of the PHPcms system with other systems to help developers better cope with challenges. 1. Basic Principles of Integration When performing system integration, it is first necessary to

In modern web development, the separation of front-end and back-end has become a very popular trend, which allows developers to better organize projects and improve the efficiency of project development. PHP and Smarty are two very commonly used technologies, which can be used to achieve front-end and back-end separation development. This article will introduce how to use PHP and Smarty to achieve front-end and back-end separation development. What is front-end and back-end separation development? In traditional web development, the front-end is mainly responsible for the presentation of the page and the logic of interaction with the back-end. The backend is mainly responsible for the business
