簡體   English   中英

如何使用ZEND模塊(不是Zend控制器)作為子域

[英]How to use ZEND modules (not Zend controller) as subdomain

我已經使用ZEND框架1.12.0版建立了我的網站。 我的網站中還有其他三個模塊(管理員,博客,圖像),我想以http : //admin.mysitename.com,http : //blog.mysitename.com,http://images.mysitename.com進行訪問分別。 但是,我無法訪問子域。 請注意:這些模塊具有不同的操作,例如更新,添加,存檔等。

.htaccess代碼:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>

Bootstrap.php:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
    /**
     * Initialize the application autoload
     *
     * @return Zend_Application_Module_Autoloader
     */
    protected function _initAppAutoload(){
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'App',
            'basePath'  => dirname(__FILE__),
        ));
        return $autoloader;
    }

    /**
     * Initialize the layout loader
     */
    protected function _initLayoutHelper(){
        $this->bootstrap('frontController');
        $layout = Zend_Controller_Action_HelperBroker::addHelper(new Amz_Controller_Action_Helper_LayoutLoader());
    }   

    public function _initRoutes(){
        $frontController = Zend_Controller_Front::getInstance();
        $router = $frontController->getRouter();

        $route = new Zend_Controller_Router_Route ('cms/:page_url/',array('controller' => 'Cms','action'=> 'index'));
        $router->addRoute('cms-page', $route);


        $router->addRoute('user', new Application_Route_User(
            'user',
            array(
                'module' => 'default',
                'controller' => 'Userdetail',
                'action' => 'index'
            )
        ));


        $routeJoin = new Zend_Controller_Router_Route ('join/:id/',array('controller' => 'Index','action'=> 'index'));
        $router->addRoute('join', $routeJoin); 


        $registration = new Zend_Controller_Router_Route ('registration/invitation/:id',array('controller' => 'Registration','action'=> 'index'));
        $router->addRoute('registration', $registration);


    }  

    /**
     *Get the PDO database connection and set it to the Registry 
     */
    protected function _initDbConfig(){
        $config = new Zend_Config($this->getOptions());
        $params = $config->database->toArray();
        $DB = new Zend_Db_Adapter_Pdo_Mysql($params);    
        $DB->setFetchMode(Zend_Db::FETCH_OBJ);
        Zend_Registry::set('DB',$DB);
    }   

    /**
     *Get the smtp information and set it to the Registry 
     */
    protected function _initSiteConfig(){           
        $registry = Zend_Registry::getInstance();
        $DB = Zend_Registry::get('DB');     
        $selectSiteConfig= "SELECT * FROM site_config order by id"; //fetching available account types  
        $resultSiteInfo = $DB->fetchAssoc($selectSiteConfig);
        $site_config=array();
        foreach($resultSiteInfo as $row){
            $site_config[$row['config_name']]=$row['config_value'];         
        }   
        Zend_Registry::set('site_config',$site_config);
    }   

    /**
     * Setup the Custom Helpers
     */
    protected function _initSetHelper(){
        Zend_Controller_Action_HelperBroker::addPrefix('Helper');
    }   

}

index.php文件:

ini_set("display_errors","on");
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));


//Ensure zend library is on include_path   
$rootDir = dirname(__FILE__);
set_include_path($rootDir . '/library' . PATH_SEPARATOR . get_include_path());    

/** Zend_Application */
require_once 'Zend/Application.php';  

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini'
);



$config = new Zend_Config_Ini('application/configs/application.ini','production');  

$siteurl  = $config->siteurl;
$sitedocroot = $config->sitedocroot;


define('SITEURL',$siteurl); //DEFINE SITE URL AS CONSTANT
define('SITEDOCROOT',$sitedocroot); //DEFINE SITE DOC ROOT AS CONSTANT
define('FORMURL',$form_url);
Zend_Registry::set('siteurl',$siteurl); //SET SITE URL IN REGISTRY
Zend_Registry::set('sitedocroot',$sitedocroot); //SET SITE DOC ROOT IN REGISTRY



$currentDate = date("Y-m-d");
define('CURDATE',$currentDate);
Zend_Registry::set('curdate',$currentDate);


$currentDateTime = date("Y-m-d H:i:s");
define('CURDATETIME',$currentDateTime);
Zend_Registry::set('curdatetime',$currentDateTime);


$detailDateForm= date("F j, Y");//March 22 2012
define('DETAILDATE',$detailDateForm);
Zend_Registry::set('detaildate',$detailDateForm);
$application->bootstrap()->run();

我遵循的步驟:

1)使用cpanel創建單獨的子域。 子域與域具有相同的DocumentRoot文件夾。

2)在application.ini文件中編寫了以下代碼(提及的代碼僅用於圖像模塊)

resources.router.routes.images.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.images.route = ":module.mysitename.com"
resources.router.routes.images.defaults.module = "images"
resources.router.routes.images.chains.index.type = "Zend_Controller_Router_Route"
resources.router.routes.images.chains.index.route = ":controller/:action/*"
resources.router.routes.images.chains.index.defaults.controller

我遵循的另一個步驟:

1)上述步驟中的步驟1。

2)在主域的bootstrap.php文件上寫入以下代碼(在_initRoutes函數上)

$router = Zend_Controller_Front::getInstance()->getRouter();

$hostnameRoute = new Zend_Controller_Router_Route_Hostname(":images.mysitename.com");

$router->addDefaultRoutes();
foreach ($router->getRoutes() as $key=>$route) {
$router->addRoute('hostname' . $key, $hostnameRoute->chain($route));

我也嘗試從其他站點獲得幫助,但是發現沒有什么重要的內容,並且大多數都提到了控制器。

我的步驟正確嗎? 請幫我。

編輯:

根據帖子(David Weinraub建議),我在application.ini上添加了以下提到的代碼

resources.modules[] = "images"

; abstract routes to be used in chaining
resources.router.routes.plain.type = "Zend_Controller_Router_Route"
resources.router.routes.plain.abstract = true
resources.router.routes.plain.route = "/:controller/:action"
resources.router.routes.plain.defaults.controller = "index"
resources.router.routes.plain.defaults.action = "index"

resources.router.routes.mysite.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite.abstract = true
resources.router.routes.mysite.route = "images.mysitename.com"
resources.router.routes.mysite.defaults.module = "images"

resources.router.routes.mysite1.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite1.abstract = true
resources.router.routes.mysite1.route = "blog.mysitename.com"
resources.router.routes.mysite1.defaults.module = "blog"

; now the actual (non-abstract) routes are chains of the abstract ones
resources.router.routes.mysite-plain.type = "Zend_Controller_Router_Route_Chain"
resources.router.routes.mysite-plain.chain = "mysite,plain"

resources.router.routes.mysite1-plain.type = "Zend_Controller_Router_Route_Chain"
resources.router.routes.mysite1-plain.chain = "mysite1,plain"

但是,這並沒有解決。 我收到以下提到的錯誤。

Warning: is_readable() [function.is-readable]: open_basedir restriction in effect. File(/home/debcho/public_html/application/../../Library/ZendX/Application/Resource/Frontcontroller.php) is not within the allowed path(s): (/home/debcho/public_html:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/debcho/public_html/library/Zend/Loader.php on line 186

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started in /home/debcho/public_html/library/Zend/Loader.php/186' in /home/debcho/public_html/library/Zend/Session.php:451 Stack trace: #0 /home/debcho/public_html/library/Zend/Session/Namespace.php(143): Zend_Session::start(true) #1 /home/debcho/public_html/application/Bootstrap.php(128): Zend_Session_Namespace->__construct('Zend_Auth_LipyU...') #2 /home/debcho/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initSetUserAccessPermission() #3 /home/debcho/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('setuseraccesspe...') #4 /home/debcho/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #5 /home/debcho/public_html/library/Zend/Application.php(355 in /home/debcho/public_html/library/Zend/Session.php on line 451

以下提到的步驟對我有用。

我們將需要在Bootstrap.php中為子域路徑路由添加一個函數_initSubDomainRoute()。 以下提到的功能成功運行。

public function _initSubDomainRoute()
{
   $pathRoute = new Zend_Controller_Router_Route(':controller/:action/*', array('controller'=>'index', 'action'=>'index'));

   $frontController = Zend_Controller_Front::getInstance();
   $router = $frontController->getRouter();

   $imageDomainRoute = new Zend_Controller_Router_Route_Hostname(
                         'image.examples.com',
                          array(
                            'module'     => 'myimage'
                          ));

   $router->addRoute('imagesdomain', $imageDomainRoute->chain($pathRoute));

   $i_pathRoute_1 = new Zend_Controller_Router_Route(':value', array('controller'=>'Details', 'action'=>'index'));
   $router->addRoute('imagesdomain1', $imageDomainRoute->chain($i_pathRoute_1));



   $jokeDomainRoute = new Zend_Controller_Router_Route_Hostname(
                        'joke.examples.com',
                         array(
                           'module'     => 'myjoke'
                         ));

   $router->addRoute('jokesdomain', $jokeDomainRoute->chain($pathRoute));


   $j_pathRoute_1 = new Zend_Controller_Router_Route(':value', array('controller'=>'Details', 'action'=>'index'));
   $router->addRoute('jokesdomain1', $jokeDomainRoute->chain($j_pathRoute_1));
}

.htaccess和index.php文件具有相同的代碼(如上所述)。 沒有修改此文件上的任何內容用於子域配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM