标题: 关于引导文件 请大家指教【解决】
dudu
新手上路
Rank: 1



UID 1109
精华 0
积分 0
帖子 10
翻译 0
原创 0
阅读权限 10
注册 2008-5-2
状态 离线
发表于 2008-6-13 10:13  资料  短消息  加为好友 
关于引导文件 请大家指教【解决】

把这种结构
[attach]74[/attach]
改成这种结构
[attach]73[/attach]
引导文件要改什么地方
这是引导文件

PHP代码如下:
final class BlogSite
{
    private 
$frontCtroller null//前端控制器变量

    
private $config null

    private 
$smarty null;

    private 
$dbAdapter null;

    private static 
$instance null;

    public static function 
getInstance()
    {
            
                
self::$instance = new BlogSite();
            
self::$instance->init();
            
self::$instance->buildFrontCtrl();                
            
self::$instance->buildDbAdapter();  

            return  
self::$instance;
    }

    public function 
__construct()
    {

    }

    private function 
init()
    {
        
Zend_Loader::registerAutoload();  
        
$this->buildConfig();
    }

    private function 
buildConfig()  // 加载config文件
    
{
        
$this->config = new Zend_Config_Ini(CONFIG_FILE,'config');

        
Zend_Registry::set('config'$this->config);     
        return 
$this->config;
    }

    private function 
buildFrontCtrl() // 加载前端控制器
    
{
        
$this->frontCtroller Zend_Controller_Front::getInstance();
        
$modules $this->config->module->toArray();
       
        foreach (
$modules as $key=>$value){
                
$module[$key] = APP_DIR DIRECTORY_SEPARATOR.'modules' DIRECTORY_SEPARATOR $key DIRECTORY_SEPARATOR $value;
        }
        
        
$this->frontCtroller->setControllerDirectory($module);
       

        
$this->frontCtroller->setParam('noViewRenderer'true);
        
$this->frontCtroller->throwExceptions(true);
        
        return 
$this->frontCtroller;
    }
    
    private function 
buildDbAdapter()//加载数据库设置
    
{
            
$this->dbAdapter Zend_Db::factory($this->config->db->adapter,$this->config->db->config->toArray());
            
            
$this->dbAdapter->query('set names ' $this->config->db->config->charset);
        
        
Zend_Registry::set('dbAdapter'$this->dbAdapter);  //注册变量      
        
return $this->dbAdapter;
    }

    public function 
run()
    {
        
$this->frontCtroller->dispatch();
    }
}

$blogsite BlogSite::getInstance();
$blogsite->run();


修改后的目录结构
[attach]75[/attach]
修改后的引导文件

PHP代码如下:

<?php

final class BlogSite
{
    private 
$frontCtroller null//前端控制器变量

    
private $config null

    private 
$smarty null;

    private 
$dbAdapter null;

    private static 
$instance null;

    public static function 
getInstance()
    {
            
                
self::$instance = new BlogSite();
            
self::$instance->init();
            
self::$instance->buildFrontCtrl();                
            
self::$instance->buildDbAdapter();  

            return  
self::$instance;
    }

    public function 
__construct()
    {

    }

    private function 
init()
    {
        
Zend_Loader::registerAutoload();  
        
$this->buildConfig();
    }

    private function 
buildConfig()  // 加载config文件
    
{
        
$this->config = new Zend_Config_Ini(CONFIG_FILE,'config');

        
Zend_Registry::set('config'$this->config);     
        return 
$this->config;
    }

    private function 
buildFrontCtrl() // 加载前端控制器
    
{
        
$this->frontCtroller Zend_Controller_Front::getInstance();
       
// $modules = $this->config->module->toArray();
       
       // foreach ($modules as $key=>$value){
        //        $module[$key] = APP_DIR . DIRECTORY_SEPARATOR.'modules' . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . $value;
       // }
        
        //$this->frontCtroller->setControllerDirectory($module);
       
$this->frontCtroller->setModuleControllerDirectoryName('controllers');
       
$this->frontCtroller->addModuleDirectory(MODULES_DIR);

        
$this->frontCtroller->setParam('noViewRenderer'true);
        
$this->frontCtroller->throwExceptions(true);
        
        return 
$this->frontCtroller;
    }
    
    private function 
buildDbAdapter()//加载数据库设置
    
{
            
$this->dbAdapter Zend_Db::factory($this->config->db->adapter,$this->config->db->config->toArray());
            
            
$this->dbAdapter->query('set names ' $this->config->db->config->charset);
        
        
Zend_Registry::set('dbAdapter'$this->dbAdapter);  //注册变量      
        
return $this->dbAdapter;
    }

    public function 
run()
    {
        
$this->frontCtroller->dispatch();
    }
}

$blogsite BlogSite::getInstance();
$blogsite->run();


还请大家指正
谢谢
                                                 ---dudu

[ 本帖最后由 dudu 于 2008-6-13 11:04 编辑 ]



 附件: 您所在的用户组无法下载或查看附件
顶部
 


PHPEye开源社区


当前时区 GMT+8, 现在时间是 2008-11-21 17:29

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.016421 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - PHPEye开源社区 - Archiver