我有一个关于在服务器上部署 Zend 项目的问题。在 localhost 上,我使用虚拟主机将文档根目录设置为 public/index.php 文件夹。
- 我现在应该如何部署它?我已经在服务器上复制了整个项目,但由于我的所有路径都错误(因为所有路径都是相对于公用文件夹设置的),它无法正常工作。
- 我该怎么办?是否可以将我的所有路径设置为相对于服务器上的主路径?在这种情况下,如何将我的应用程序重定向到任何控制器?或者也许我只需要在服务器上创建虚拟主机但我没有权限这样做:/?
我需要一些建议,谢谢
应用程序.ini:
[production]
phpSettings.display_startup_errors = 0
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.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] =
resources.db.isDefaultTableAdapter = true
resources.db.adapter = PDO_MYSQL
resources.db.params.charset = "utf8"
resources.db.params.host = HOST
resources.db.params.username = "p"
resources.db.params.password = "***"
resources.db.params.dbname = "p"
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
索引.php:
<?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') : 'production'));
defined('DESTINATION_IMAGES') || define('DESTINATION_IMAGES', './usersImages/');
defined('TRUE_STORY_EMAIL') || define('TRUE_STORY_EMAIL', 'mmm@gmail.com');
defined('TRUE_STORY_NAME') || define('TRUE_STORY_NAME', 'True story team');
// 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();
.htaccss:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
phpinfo();
w 加载的模块我有 mod_rewrite 所以可能是启用的。
-----------------------------------------
--------编辑 04.05.2011 -----
我再次在服务器上部署了项目,并且设置了 RewriteBase /~user2/Project2/public
现在 URL 映射正在工作(可能是我第一次部署它时出现错误,这就是它不起作用的原因)。
但我仍然对这个项目有问题。当我去 Auth 控制器时:
public function indexAction() {
// action body
$form = new Application_Form_Login();
$request = $this->getRequest();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
try {
if ($this->_process($form->getValues())) {
$userDT = new Application_Model_DbTable_User();
$idUser = Zend_Auth::getInstance()->getIdentity()->id;
if ($userDT->isConfirmed($idUser)) {
$this->_helper->redirector->gotoRoute(
array(
'controller' => 'index',
'action' => 'index'
)
);
} else {
$form->setDescription('Your account is not confirmed!');
Zend_Auth::getInstance()->clearIdentity();
$this->_helper->redirector->gotoRoute(
array(
'controller' => 'Registration',
'action' => "step",
'idUser' => $idUser
)
);
}
} else {
$form->setDescription('There was an error. Try to log in once again please');
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
$this->view->form = $form;
}
在页面上我只能看到: 我不知道这意味着什么,因为我检查不同控制器中的重定向是否正常工作意味着我的项目看到 zend 库所以我不明白为什么它不创建表单在视图中?
风景:
<?php $this->headTitle('Login'); ?>
<h1>Login</h1>
<?php echo $this->form->setAction($this->url()); ?>