我正在开发一个项目,我正在使用Zend_Hostname_Router_Route。
我的申请很简单。我有一个名为dev的模块,我想将其路由到dev子域。我在这里和其他网站上阅读了一些文章,试图了解问题所在。
我在我的应用程序中使用ZF 1.12。我正在appllication.ini文件中使用Zend_Hostname_Router_Route,如下所示:
[production]
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] =
resources.view.encoding = "UTF-8"
resources.view.doctype = "HTML5"
resources.view.contentType = "text/html; charset=UTF-8"
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.db.adapter = "PDO_SQLITE"
resources.db.params.dbname = APPLICATION_PATH "/../data/db/guestbook.db"
[development:production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
resources.db.adapter = "PDO_SQLITE"
resources.db.params.dbname = APPLICATION_PATH "/..application/db/guestbook-dev.db"
resources.router.routes.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.route = "dev.michaeldrowan.com"
resources.router.routes.chains.dev.type = "Zend_Controller_Router_Route"
resources.router.routes.chains.dev.route = ":controller/:action/"
resources.router.routes.chains.dev.defaults.module = "dev"
resources.router.routes.chains.dev.defaults.controller = "index"
resources.router.routes.chains.dev.defaults.action = "index"
ZF快速入门教程中的应用程序。所以我不应该在设置它时遇到问题。我试过两个index.php。在public_html和下面的文件夹中的一个子域中(这是我的主机放入的位置)。子域中的索引指向dev模块。我也尝试过这样做的方式,就是zf快速入门教程
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../michaeldrowan /application/'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../../library'),
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'
);
?>
并且dev中的索引是:
<?php
// 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') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
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'
);
$application->bootstrap()
->run();
?>
我试图通过将“生产”改为“开发”来指向两者中的模块。我甚至试过'开发:生产'
我还尝试将应用程序指向模块配置,并尝试将应用程序设置到模块。
我的事情已经不多了。我希望有人可以帮助我。
答案 0 :(得分:0)
如果您使用Apache,请在.htaccess
中写下此内容RewriteCond %{HTTP_HOST} ^([a-zA-Z\-\.]+)\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ index.php?someparam=%1 [QSA]
然后您可以在IndexController中访问子域名:
if ($this->getRequest()->getParam('someparam') == 'dev') {
// use routing
}