I am really new to Zend Framework and am using it on regular Apache 2 + PHP server.
I want to use my models which extend Zend_Table_Abstract. I put it in my /application/models directory but these files do not even get included (they have syntax errors but my app works just fine). What are the required actions to get them included? What should be done in Bootstrap and what naming conventions should be followed? I’ve seen people using just regular names like Users or 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 (some code is there just because I copied it from some example or answer)
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
You need to change the way you name your models, because Zend autoloader can’t simply find the right file idue to way it loads models. So instead of having model like this:
you should name it like this:
and then instantiate:
Please note models are mapped differently and your
Application_Model_Languagemodel class have to be placed inapplication/models/Language.phpfor this to work.