16080891(Lamp→研讨会)

CI的视图能用smarty (转贴 英文版)

上一篇 / 下一篇  2008-04-09 15:30:56 / 个人分类:网络转载

CI的视图能用smarty (转贴 英文版)

In this article you will learn how to install and use Smarty as a template engine with Code Igniter Framework.

Demo

Adownloadabledemo (including Smarty-2.6.18) is available from
http://funcs.org/downloads/code-igniter/code-igniter-smarty.zip(~ 200 KB)

update (2007-12-13):  an option added to pass params to mysmarty without calling assign Smarty method.
$this->mysmarty->view('module/func', $params);

http://funcs.org/downloads/code-igniter/code-igniter-smarty-2.zip(~ 200 KB)

Code Igniteris a very good framework but there does have a *native* support for theSmarty template engine, it uses PHP code as template contents.

How to integrate

Things that you should keep in mind (when integrating this example into your projects)

1. You should add 'mysmarty' to autoloaded libraries in application/config/autoload.php

Example:
$autoload['libraries'] = array('database', 'mysmarty');

2. Copy Mysmarty.php to application/libraries

at the beginning of the file Mysmarty.php you can see the original smarty file structure.
I like this approach because it makes the updates easy, and/or downgrades (if any) in case of buggy new releases.

example
---
require "Smarty-2.6.18/libs/Smarty.class.php";
--


Example Usage of Smarty in Code Igniter:

application/controllers/welcome.php
-----------------------------------

mysmarty->assign('test', 'Hello World.');
$this->mysmarty->view('smarty');
}
}
-----------------------------------
Note:
$this->mysmarty should be available because we are auto loading this library.

view method is used to make an easier transition from code igniter's templates to Smarty ones.
view method also adds a '.tpl' extension if is not specified.


Example Smarty Template: application/views/smarty.tpl
-----------------------------------

{$test}

Def: {$def|default:'n/a'}
-----------------------------------

The file should be accessible via:
http://domain.com/path/to/code-igniter/index.php/welcome/smarty

wherepath/to/code-igniteris the path to code igniter index.php file.

TAG: 网络转载

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar