国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

CI框架整合smarty步驟詳解

Original 2017-01-05 10:51:42 252
abstract:本文詳細(xì)講述了CI框架整合smarty步驟。分享給大家供大家參考,具體如下:Ci結(jié)合smarty的配置步驟:1. 第一步配置ci和下載smarty的模板個人喜歡用(Smarty-3.1.8)這個版本。2. 第二部把下載到的smarty版本解壓然后把里面的libs文件改名為smarty然后把這個文件拷到ci\application\libraries目錄下面3. 在ci\application\li

本文詳細(xì)講述了CI框架整合smarty步驟。分享給大家供大家參考,具體如下:

Ci結(jié)合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我們的配置到這里就已經(jīng)成功了,接下來我們開始測試

測試的第一步先建立一個控制器:

1. 在\application\controllers下建立一個文件名為ceshi.php的文件,文件內(nèi)容

<?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的文件,文件內(nèi)容為

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

更多關(guān)于CI框架整合smarty步驟詳解請關(guān)注PHP中文網(wǎng)(m.miracleart.cn)其他文章!

Release Notes

Popular Entries