search
HomeBackend DevelopmentPHP TutorialDetailed explanation of steps to integrate smarty with CI framework, detailed explanation of smarty with ci framework_PHP tutorial

Detailed explanation of the steps of CI framework integration smarty, detailed explanation of ci framework smarty

This article describes in detail the steps of CI framework integration smarty. Share it with everyone for your reference, the details are as follows:

Ci combined with smarty configuration steps:

1. The first step is to configure ci and download the smarty template. I like to use this version (Smarty-3.1.8).

2. In the second step, unzip the downloaded smarty version and rename the libs file inside to smarty, then copy this file to the ciapplicationlibraries directory

3. Create a file under the ciapplicationlibraries directory. The file name can be customized. For example, see a tp.php document.

4. Open tp.php with a compiler and write the following code:

<&#63;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. Create a ciapplicationtemplates_c folder

6. Open the ciapplicationconfigautoload.php file

$autoload['libraries'] = array();

changed to:

$autoload['libraries'] = array('database','tp');

OK our configuration has been successful here, let’s start testing

The first step in testing is to create a controller:

1. Create a file named ceshi.php under applicationcontrollers, with file content

<&#63;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. Create a template file. Create a file named ceshi.html in the ciapplicationviews directory. The content of the file is

 <!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>

Finally enter the address http://localhost/ci/application/index.php/ceshi (the idea ci represents the root directory where you place the files in the ci framework). After running, you will see that you have successfully configured smarty. page, the integration and testing of ci and smarty are completed here

Readers who are interested in more CodeIgniter-related content can check out the special topics of this site: "Basic Tutorial for Getting Started with Smarty Templates", "Introductory Tutorial for CodeIgniter", "Advanced Tutorial for CI (CodeIgniter) Framework", "Summary of Excellent PHP Development Framework" ", "ThinkPHP introductory tutorial", "ThinkPHP common methods summary", "Zend FrameWork framework introductory tutorial", "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127843.htmlTechArticleDetailed explanation of the steps of CI framework integration smarty, Detailed explanation of ci framework smarty This article describes in detail the steps of CI framework integration smarty. Share it with everyone for your reference, the details are as follows: Configuration steps of Ci combined with smarty...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php如何使用CI框架?php如何使用CI框架?Jun 01, 2023 am 08:48 AM

随着网络技术的发展,PHP已经成为了Web开发的重要工具之一。而其中一款流行的PHP框架——CodeIgniter(以下简称CI)也得到了越来越多的关注和使用。今天,我们就来看看如何使用CI框架。一、安装CI框架首先,我们需要下载CI框架并安装。在CI的官网(https://codeigniter.com/)上下载最新版本的CI框架压缩包。下载完成后,解压缩

PHP中如何使用CI框架PHP中如何使用CI框架Jun 27, 2023 pm 04:51 PM

PHP是一种流行的编程语言,广泛应用于Web开发。CI(CodeIgniter)框架是PHP中最受欢迎的框架之一,它提供了一整套现成的工具和函数库,以及一些流行的设计模式,让开发人员能够更加高效地开发Web应用程序。本文将介绍使用CI框架开发PHP应用程序的基本步骤和方法。了解CI框架的基本概念和结构在使用CI框架之前,我们需要先了解一些基本的概念和结构。下

php如何使用CI4框架?php如何使用CI4框架?Jun 01, 2023 pm 02:40 PM

PHP是一种广泛使用的服务器端脚本语言,而CodeIgniter4(CI4)是一个流行的PHP框架,它提供了一种快速而优秀的方法来构建Web应用程序。在这篇文章中,我们将通过引导您了解如何使用CI4框架,来使您开始使用此框架来开发出众的Web应用程序。1.下载并安装CI4首先,您需要从官方网站(https://codeigniter.com/downloa

PHP中的CI框架指南PHP中的CI框架指南May 22, 2023 pm 07:10 PM

随着互联网的发展和不断地融入人们的生活,网络应用的开发变得越来越重要。PHP作为一种众所周知的编程语言,已经成为了开发互联网应用程序的首选语言之一。而开发人员们可以使用众多的PHP框架来简化开发过程,其中最受欢迎的之一是CodeIgniter(CI)框架。CI是一个强大的PHPweb应用框架,它拥有轻量级、简单易用、优化性能等特点,可以让开发人员快速地构建

如何使用PHP和Smarty实现前后端分离开发如何使用PHP和Smarty实现前后端分离开发Jun 25, 2023 pm 01:46 PM

在现代web开发中,前后端分离已经成为了一个非常流行的趋势,它能够让开发者们更好地组织项目并且提高了项目开发的效率。PHP和Smarty是两个非常常用的技术,它们可以用来实现前后端分离的开发方式。本文将会介绍如何使用PHP和Smarty来实现前后端分离开发。什么是前后端分离开发在传统的web开发中,前端主要负责页面的呈现以及与后端交互的逻辑。后端则主要负责业

PHP中的模板引擎Smarty初探PHP中的模板引擎Smarty初探May 11, 2023 pm 05:15 PM

现如今,网站的开发离不了一个重要的组成部分——模板引擎。模板引擎是指一种将页面模板和数据结合起来生成具有特定格式的html代码的工具。在各种网站开发框架中,模板引擎是一个必不可少的组件,因为模板引擎可以大量减少代码的重复性和提高页面的动态性。其中一种最常见和流行的模板引擎是Smarty。Smarty是一个基于PHP语言开发的DSL(DomainSpecif

ci框架如何引入cssci框架如何引入cssDec 26, 2023 pm 05:20 PM

CI框架中引入CSS样式的步骤如下:1、准备CSS文件;2、将CSS文件存储在CI框架项目的适当位置;3、在需要使用CSS样式的页面中,通过HTML的<link>标签引入CSS文件;4、在HTML元素中使用CSS类或ID名称来应用相应的样式即可。

PHP开发中如何使用Smarty模板引擎PHP开发中如何使用Smarty模板引擎Jun 27, 2023 pm 01:28 PM

作为一名PHP开发者,使用模板引擎是理所当然的选择。Smarty是一种流行的模板引擎,它提供了一种将HTML/CSS/JavaScript与PHP代码分离的方式,使开发人员能够更好地组织和管理项目。在本文中,我们将学习在PHP开发过程中如何使用Smarty模板引擎。一、安装Smarty在之前,我们必须安装Smarty。在本文中,我们将使用Composer安装

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools