cakephp: 和Smarty集成

試了兩個方法:
 一個是: 
http://projects.simpleteq.com/CakePHP/smarty.html
 另一個是:http://cakeforge.org/snippet/detail.php?type=snippet&id=6
 
 怎麼說 
http://cakeforge.org/snippet/detail.php?type=snippet&id=6 也是官方的實現,搞了半天死活不成功.
 沒辦法用第一個吧

1. 下載 http://projects.simpleteq.com/CakePHP/smarty.zip,解壓並放置於app/views目錄
2. 下載(
http://smarty.php.net/do_download.php?download_file=Smarty-2.6.18.tar.gz)並安裝Smarty,置於/vendors/smarty目錄
3. 在控制器中設置屬性$view爲'Smarty',向控制器表示我使用Smarty作爲View層,而不是使用cake內置的View. 

public $view = 'Smarty';

4. 模板位置和ctp模板的位置一樣,知識擴展名爲 .tpl
5. 在控制器中設置模板變量
 

$this->set('var', $var);

6. 在模板中輸出變量
 {$var}
 
exmaple:

class SomeObjectsController extends AppController
{
 
var $name = "SomeObjectsr"
;
 
var $helpers = array("Html", "Text"
);
 
 
function
 index_s()
 {
  
$this->view = "Smarty"
;
  
$this->set("SomeValue", "Called using smarty's renderer."
);
  
return
;
 }
 
 
function
 index()
 {
  
$this->set("SomeValue", "Called using the CakePHP's built-in renderer."
);
  
return
;
 }  
}

模板文件

<h1>Head 1</h1>
<p>{$html->link('這是一個連接', 'http://blog.csdn.net/httpnet')}</p>
<p>{$SomeValue}</p>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章