zoukankan      html  css  js  c++  java
  • ci框架与smarty的整合

    ci框架与smarty的整合

    来源:未知    时间:2014-10-20 11:38   阅读数:108   作者:xbdadmin

    [导读] Ci 和 smarty 的完美结合 Ci 结合 smarty 的配置步骤: 1.第一步配置 ci 和下载 smarty 的模板个人喜欢用( Smarty-3.1.8)这个版本。 2.第二部把下载到的 smarty 版本解压然后把里面的 libs文件改名...

    Cismarty的完美结合

    Ci结合smarty的配置步骤:

    1. 第一步配置ci和下载smarty的模板个人喜欢用(Smarty-3.1.8)这个版本。

    2. 第二部把下载到的smarty版本解压然后把里面的libs文件改名为smarty然后把这个文件拷到ciapplicationlibraries目录下面

    3. 在ciapplicationlibraries这个目录下面建立一个文件,文件名可以自定义,例如见一个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. 在建立一个ciapplication emplates_c文件夹

    6. 打开ciapplicationconfigautoload.php文件把$autoload['libraries'] = array();改成$autoload['libraries'] = array('database','tp');

    OK我们的配置到这里就已经成功了,接下来我们开始测试

     测试的第一步先建立一个控制器:

    1. 在applicationcontrollers下建立一个文件名为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');  

            }  

     5.建立模板文件在ciapplicationviews目录下建立文件名为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成功的页面,到这里cismarty的整合以及测试就完工了


     




  • 相关阅读:
    Python函数之冒泡算法
    Python内置函数之--open
    Python 基础5:内置函数一
    27、数组的操作
    26、字符串的操作
    25、求最大公约数和最大公倍数——循环
    24、输出九九口诀乘法表——循环
    查找【操作】
    04、结构体两种传参形式
    1、电脑联网小技巧:网络共享之台式机、笔记本、手机
  • 原文地址:https://www.cnblogs.com/muxiaoye/p/7805d565fb5a50cbc0807f3855148e38.html
Copyright © 2011-2022 走看看