beautylove 发表于 2008-4-6 19:45:32

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

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

Demo

A downloadable demo (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

where path/to/code-igniter is the path to code igniter index.php file.


附件是对应上面对两个文件。

[ 本帖最后由 beautylove 于 2008-4-6 19:48 编辑 ]

beautylove 发表于 2008-4-6 19:50:49

http://devcha.blogspot.com/2007/12/smarty-as-template-engine-in-code.html

这是原文地址!!N-人 兄弟的版权意识比较好。。:handshake

analyzer 发表于 2008-4-11 18:16:50

原帖由 beautylove 于 2008-4-6 19:50 发表 http://codeigniter.org.cn/forums/images/common/back.gif
http://devcha.blogspot.com/2007/12/smarty-as-template-engine-in-code.html

这是原文地址!!N-人 兄弟的版权意识比较好。。:handshake

IF了YOU

荒野无灯 发表于 2010-7-14 16:28:02

爬墙去看了下原文。

as3291363 发表于 2010-8-12 16:27:10

爬墙去看了下原文。
荒野无灯 发表于 2010-7-14 16:28 http://codeigniter.org.cn/forums/images/common/back.gif


    感覺怎麼樣啊?

13880411700 发表于 2011-10-31 15:42:06

感谢楼主了
页: [1]
查看完整版本: CI的视图能用smarty (转贴 英文版)