zendframework和smarty整合

一、 smarty引用
    把这段代码添加到zendframework根目录下的index.php里,
      include './library/Smarty/libs/Smarty.class.php';
      $smarty = new Smarty();
      $smarty -> template_dir = "./application/views/scripts/";//设置模板显示路径
      $smarty -> compile_dir = "./application/views/scripts/templates_c";
      $smarty -> left_delimiter = "<{";
      $smarty -> right_delimiter = "}>";
      $registry = Zend_Registry::getInstance();
      $registry->set('smarty',$smarty); 
二、创建smartycontroller.php文件
   class SmartyController extends Zend_Controller_Action
   {
    function init() {
        $this->registry = Zend_Registry::getInstance();
        $this->view = $this->registry['smarty'];
        $baseurl = $this->_request->getBaseUrl();
        $this->view->assign('baseurl',$baseurl);
    }
    function indexAction(){
        $title = "运行成功了。";
        $this->view->assign('title',$title);
        $this->view->display('smarty/index.phtml');
    }
  }
三、在/views/scripts/下创建smarty文件夹,在文件夹里创建index.phtml
   <p>hello world</p>
   <p><{$title}></p>

四、在浏览器里输入localhost/smarty/index;

   运行成功了。
  

posted @ 2014-06-20 10:44  blogjaken  阅读(286)  评论(0编辑  收藏  举报