ZF0.15成功整合Smarty2.6.14!傻瓜化教程

来源:互联网 发布:淘宝差评怎么写 编辑:程序博客网 时间:2024/06/14 18:00
虽然论坛上已经有ZF整合Smarty的文章,不过可能是我水平太菜,老是试验不成功,不过今晚,就是现在啦,在自己的机子上,终于成功整合ZF+Smarty,以前是个人的小小心得...[/color]

1:目录结构:

+ www
- zf
   --Application
     Controllers
     Models
    ---Views
     Cache
     Configs
     Tpl
     Tpl_c
   --library
     +Zend
2. Apache启用Rewrite

3. .htaccess文件的内容
RewriteEngine on
RewriteRule !/.(js|ico|gif|jpg|png|css)$ index.php
php_value include_path "../library"
   


其实一样的。
主要是你没注意看。
我一直也是用ZF和Smarty结合的!
我的index.php也是这样的。
把V设置成放摸板的地方。

PHP代码如下:

<?
set_include_path('../library');
include 
'Zend.php';
include 
'Smarty/Smarty.class.php';
include 
'./Application/Models/Datebase.php';  //数据库操作类
include'../FCKeditor/fckeditor.php'//在线编辑器
function __autoload($class)
{
  
Zend::loadClass($class);
}

$db = new Database();
Zend::register('db'$db);                                      // 注册数据库超作对象到对象仓库


$tpl=  new Smarty();
$tpl->caching=false;                                          //缓存
$tpl->debugging=false
$tpl->template_dir="./Application/Views"
$tpl->compile_dir="./Application/Views/Views_c";
$tpl->cache_dir "./Application/Views/Cache";  
Zend::register('tpl',$tpl);

$oFCKeditor = new FCKeditor('FCKeditor');
Zend::register('oFCKeditor',$oFCKeditor);

$router = new Zend_Controller_RewriteRouter();
$controller Zend_Controller_Front::getInstance();
$controller->setRouter($router);

$controller->setControllerDirectory('./Application/controllers');
$controller->dispatch();
?> 




4.配置Apache,zf/www为网站根目录

5.文件位置:
  zf/www : 放置 .htaccess  index.php
  Application/Controllers :放置IndexController.php
  Application/Views : 放置 Tpl,Tpl_c,Cache,Configs四个文件夹..Tpl文件夹里放模板文件..

6.文件内容:

  zf/www/index.php:

<?php

include 'Zend.php';

include 'Zend/View/Smarty/Smarty.class.php';

define('SITE','../Application/Views/');

$tpl=new Smarty;

$tpl->template_dir = SITE.'Tpl';

$tpl->compile_dir = SITE.'Tpl_c';

$tpl->cache_dir = SITE.'Cache';

$tpl->config_dir = SITE.'Configs';

Zend::register('tpl',$tpl);

function __autoload($class) {
   
    Zend::loadClass($class);
}

$router = new Zend_Controller_RewriteRouter();

$controller = Zend_Controller_Front::getInstance();

$controller->setRouter($router);

$controller->setControllerDirectory('../Application/Controllers');

$controller->dispatch();
?>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Application/Controllers/IndexController.php

<?php

class IndexController extends Zend_Controller_Action {
      
    public function indexAction() {
        
        $tpl=Zend::registry('tpl');

        $tpl->assign('title','我是誰啊');

        $tpl->assign('content','我是從哪裡來的呀');

        $tpl->display('index.html');
    }
   
    public function noRouteAction() {
        
        $this->_redirect('./');

    }

}
?>

模板文件就萝卜青菜了....呵呵...教程到些结束...