+ -
当前位置:首页 → 问答吧 → zendframework中URL 总是 index中的内容怎么回事?

zendframework中URL 总是 index中的内容怎么回事?

时间:2011-10-08

来源:互联网

index.php 入口文件
=================
    error_reporting(E_ALL|E_STRICT);//错误报告级别
    date_default_timezone_set('Asia/Shanghai');//默认时区 东八区
    set_include_path('.' .PATH_SEPARATOR .'./library'.PATH_SEPARATOR .'./application/models/'.PATH_SEPARATOR . get_include_path());
    require_once "Zend/Loader/Autoloader.php"; //载入zend框架
    Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true); //静态载入自动类文件
    $registry = Zend_Registry::getInstance();
    //配置数据库参数,并连接数据库
    $config=new Zend_Config_Ini('./application/config/config.ini',null, true);
    Zend_Registry::set('config',$config);
    $dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config->toArray());
    //$dbAdapter->query('set names utf8');
    Zend_Db_Table::setDefaultAdapter($dbAdapter);
    Zend_Registry::set('dbAdapter',$dbAdapter);
    //设置视图
    $view = new Zend_View();
    $view->setScriptPath('./application/views/scripts/');//设置模板显示路径
    $registry['view'] = $view;//注册View
   
    //设置控制器
    $frontController =Zend_Controller_Front::getInstance();
    $frontController->setBaseUrl('/zend')//设置基本路径
                  ->setParam('noViewRenderer', true)
                  ->setParam('useDefaultControllerAlways', true)
                  ->setControllerDirectory('./application/controllers')
                  ->throwExceptions(true)
                  ->dispatch();
============================
目录结构:
*****************
/application
       config
       controllers
              indexController.php
       models
       views
             index
                   index.html
                   add.html
/library
index.php
=========================================
indexController.php 文件内容
****************************
class IndexController extends Zend_Controller_Action{
    public function init(){
           $this->registry = Zend_Registry::getInstance();
           $this->view = $this->registry['view'];
           $this->view->baseUrl = $this->_request->getBaseUrl();
    }
   
    public function index(){
        echo "This is index page!";
    }
   
    public function add(){
        echo "This is add page~~~[add]";
    }
}
============================
如果正常的话,
我打入url/zend/index/add
应该出来的是:     This is add page

但出来的却是       This is index page

作者: pjcn   发布时间: 2011-10-08

自己顶一下吧!

作者: pjcn   发布时间: 2011-10-08