0

I am using Zend_Application_Bootstrap_Bootstrap, but framework can't load modeles.

Index.php

define('ROOT_PATH', realpath(dirname(dirname(__FILE__))));
define('APP_PATH', realpath( ROOT_PATH . '/application'));

set_include_path(realpath(ROOT_PATH . '/library') . PATH_SEPARATOR . get_include_path());

require_once 'Zend/Application.php';
$app = new Zend_Application('dev', APP_PATH . '/configs/application.ini');
$app->bootstrap()->run();

Application.ini

bootstrap = APP_PATH "/Bootstrap.php"

phpSettings.display_errors = on
phpSettings.display_startup_errors = on
phpSettings.error_reporting = E_ALL|E_STRICT
phpSettings.date.timezone = "Europe/London"

resources.frontController.controllerDirectory = APP_PATH "/controllers"
resources.frontController.throwExceptions = on
resources.view.encoding = "UTF-8"
resources.view.contentType = "text/html;charset=utf-8"
resources.view.doctype = "XHTML1_STRICT"
resources.layout.layoutPath = APP_PATH "/views/layouts"
resources.layout.layout = "layout"
resources.db.adapter = "Pdo_Mysql"
resources.db.params.host = "localhost"
resources.db.params.dbname = "foo"
resources.db.params.username = "user"
resources.db.params.password = "password"
resources.db.params.charset = "utf8"

Bootstrap.php:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}

Folder tree:

Myproject->
/application
   /configs
   /controllers
   /models
      /Mytest.php
   /views
   Bootstrap.php
/public
   index.php

Problem: I trying to create new Mytest() in controller, but i get "class not found in..." When I add to bootstrap Zend_Loader::loadClass('Mytest', APP_PATH . '/models/') everything works.

My questions is, how to setup Zend_Application_Bootstrap_Bootstrap via application.ini to autoload models folder ?

Thank you.

1 Answer 1

1

Model classes are by default named in ZF under 'Application' namespace. So your class would be named as 'Application_Model_Mytest'

You can set the default namespace 'Application' by adding this to the application.ini

appnamespace = "Application"
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, it worked. But it is possible to have model classes named in old way? I mean I don't want to use prefix Application_Model_. Tryed to set (but prefix Model_ is still needed): appnamespace = "Application" I used old zend bootstrap before (inly included class Bootstrap {}) and there it was possible.
To autoload a class named MyModel that resides in the file application/models/MyModel.php, you could add the application/models folder to your include_path and set the standard autoloader as the fallback autoloader. But prefixing with at least some pseudo-namespacing - whether a full Application_Model_ or even just Model_ still strikes me as a good practice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.