Reputation: 596
I have built my website using ZEND framework version 1.12.0. There are three other modules (admin, blog, images) in my site that i want to access as http://admin.mysitename.com, http://blog.mysitename.com, http://images.mysitename.com respectively. But, i am failing to access the subdomain. Please note: the modules have different action as well like update, add, archive etc.
.htaccess code:
<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();
Steps i have followed:
1) Created separate sub-domains using cpanel. The subdomain have same DocumentRoot folder with domain.
2) Wrote the below mentioned code in application.ini file (Mentioned the code only for images module)
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
Another steps i have followed:
1) Step 1 from above mentioned steps.
2) Wrote the below mentioned code on main domain's bootstrap.php file (on _initRoutes function)
$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));
I tried to get help from other site as well but found nothing important and most of them are mentioned for controller.
Is my steps are correct? Please help me on this.
EDIT:
As per the post (suggested by David Weinraub), i have added below mentioned code on 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"
But, this did not solve. I am getting the below mentioned error.
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
Upvotes: 1
Views: 1926
Reputation: 596
The below mentioned steps worked for me.
We will require to add a function _initSubDomainRoute() in Bootstrap.php for the subdomain path routes. The below mentioned function worked successfully.
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));
}
The .htaccess and index.php file has the same(above mentioned) code. Did not modify anything on this file for sub-domain configuration.
Upvotes: 1