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

虽然 论坛上已经有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('./');

    }

}
?>

模板文件就萝卜青菜了....呵呵...教程到些结束... 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值