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对象->在控制器的方法内取出该对象->进行赋值,显示操作



  • 相关阅读:
    SqlServer 利用临时表批量添加&&修改数据库表中的数据
    有关Linux的实时性
    烟囱式到SOA再到微服务
    消费金融前世今生
    其它 一加7t禁止系统更新
    电商 相关底层知识
    CRMEB 基础 列表拖动排序2
    CRMEB 基础 列表拖动排序1
    前端 table排序
    MacBook 关闭访客登陆
  • 原文地址:https://www.cnblogs.com/iLoveMyD/p/2387541.html
Copyright © 2011-2022 走看看