zoukankan      html  css  js  c++  java
  • zend framework集成smarty

    ------zf的入口文件-index.php---------

    <?php
    //根据网站目录结构设定包含路径
    //zf库的路径视情况而定
    $root = str_replace('\\', '/', dirname(__FILE__));
    define('ROOT', $root);
    ini_set('include_path',
    ini_get('include_path').
    PATH_SEPARATOR.ROOT.'/library/'.
    PATH_SEPARATOR.ROOT.'/library/Zend/'.
    PATH_SEPARATOR.ROOT.'/application/models/'.
    PATH_SEPARATOR.ROOT.'/smarty/');
    require_once('Zend/Loader.php');//加载Zend_Loader类为__autoload()函数体内的语句做准备(手动加载一次,以后再需要其他类时就不用再手动加载了)
    function __autoload($class)
    {
    Zend_Loader::loadClass($class);//有了这一句的处理,就不用再显式的require_once(···)下面那句require_once();就不用写了
    }
    //require_once ('Zend/Controller/Front.php');
    //Zend_Controller_Front::run(ROOT.'/application/controllers');

    $frontController = Zend_Controller_Front::getInstance();
    $frontController->setParam('noViewRenderer',true);//关掉zf自带的view,看清楚noViewRenderer
    $registry = new Zend_Registry(); //生成一个注册表实例用来存放smarty实例
    require_once('Smarty.class.php');
    $views = new Smarty();
    $registry->set('view', $views);//注册成全局变量方便在其他文件中使用
    $frontController->run(ROOT.'/application/controllers');

    --------------HelloController.php-----------------------

    <?php
    require_once('Zend/Controller/Action.php');
    class HelloController extends Zend_Controller_Action
    {
    public function helloAction()
    {
    $smarty = Zend_Registry::get('view');//从注册表中取出smarty对象
    $smarty->assign('data','zhangsan');//使用smarty对象
    $smarty->display('hello.tpl');
    }

    }

    ---------hello.tpl-------------

    <!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>smarty</title>
    </head>
    <body>
    收到变量:{$data}
    </body>
    </html>

    在zf入口文件中生成smarty对象->注册smarty对象->在控制器的方法内取出该对象->进行赋值,显示操作



  • 相关阅读:
    浅谈数论
    浅谈数论
    bzoj2190 [SDOI2008]仪仗队
    bzoj2190 [SDOI2008]仪仗队
    35.QQ大数据模型
    34.函数指针数组和多线程
    33.函数指针相关问题
    32.分配数组的方式
    31.内存分配四大函数以及栈上分配内存
    30.锯齿数组
  • 原文地址:https://www.cnblogs.com/iLoveMyD/p/2387541.html
Copyright © 2011-2022 走看看