我对 Zend Framework 非常陌生,并且在常规 Apache 2 + PHP 服务器上使用它。
我想使用扩展 Zend_Table_Abstract 的模型。我把它放在我的 /application/models 目录中,但这些文件甚至没有被包含(它们有语法错误,但我的应用程序工作得很好)。需要采取哪些措施才能将它们包括在内?在 Bootstrap 中应该做什么以及应该遵循哪些命名约定?我见过人们只使用常规名称,例如Users或Articles。
/application/models/Languages.php:
<?php
adasdasdadasd
echo 'hi';
class Languages extends Zend_Db_Table_Abstract {
protected $_name = 'languages';
}
/application/controllers/LanguageController.php
<?php
class LanguagesController extends Zend_Controller_Action {
public function indexAction() {
$languages = new Languages();
$this->view->languages = $languages->select();
}
}
/application/Bootstrap.php
(有一些代码只是因为我从一些示例或答案中复制了它)
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initAutoload() {
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH)
);
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace(array('Application_'));
return $moduleLoader;
}
protected function _initResourceAutoloader()
{
$autoloader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' => 'Application_',
));
return $autoloader;
}
protected function _initFrontController()
{
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory(APPLICATION_PATH . '/controllers');
if ($controller->getParam('bootstrap') === null) {
$controller->setParam('bootstrap', $this);
}
return $controller;
}
protected function _initApplication() {
}
protected function _initModuleConfig()
{
}
protected function _initLayout(){
return Zend_Layout::startMvc();
}
protected function _initViewHelpers() {
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('My Application');
$view->headLink()->appendStylesheet('css/general.css');
$view->headLink()->appendStylesheet('css/navigation.css');
}
protected function _initNavigation() {
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
}
}
/application/configs/application.ini
:
[production]
; Models
includePaths.models = APPLICATION_PATH "/models/"
; Debug output
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
; Bootstrap
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
; Database
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.dbname = "dabase"
resources.db.params.username = "root"
resources.db.params.password = "password"
resources.db.isDefaultTableAdapter = true
[development : production]
; Debug output
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
; Database
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.dbname = "dabase"
resources.db.params.username = "root"
resources.db.params.password = "password"
resources.db.isDefaultTableAdapter = true