Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the ZF Manual:</p> <blockquote> <p><strong>Create a Model and Database Table</strong></p> <p>Before we get started, let's consider something: where will these classes live, and how will we find them? The default project we created instantiates an autoloader. We can attach other autoloaders to it so that it knows where to find different classes. Typically, we want our various MVC classes grouped under the same tree -- in this case, application/ -- and most often using a common prefix.</p> <p><strong>Zend_Controller_Front</strong> has a notion of "modules", which are individual mini-applications. Modules mimic the directory structure that the zf tool sets up under application/, and all classes inside them are assumed to begin with a common prefix, the module name. application/ is itself a module -- the "default" or "application" module. As such, we'll want to setup autoloading for resources within this directory.</p> <p><strong>Zend_Application_Module_Autoloader</strong> provides the functionality needed to map the various resources under a module to the appropriate directories, and provides a standard naming mechanism as well. An instance of the class is created by default during initialization of the bootstrap object; your application bootstrap will by default use the module prefix "Application". As such, our models, forms, and table classes will all begin with the class prefix "Application_".</p> </blockquote> <p>Since Zend_Application_Module_Autoloader is loaded by default, you should only need to bootstrap your application (you don't have to run the front controller) as per the example at the of this answer. </p> <p>If you don't want to bootstrap your application, you could short circuit the resource loading by initialising Zend_Application_Module_Autoloader yourself:</p> <pre><code>$autoloader = new Zend_Application_Module_Autoloader(); </code></pre> <p>As you can see from the code, the __construct of this class calls initDefaultResourceTypes(), with all the goodies you are looking for:</p> <pre><code>class Zend_Application_Module_Autoloader extends Zend_Loader_Autoloader_Resource { /** * Constructor * * @param array|Zend_Config $options * @return void */ public function __construct($options) { parent::__construct($options); $this-&gt;initDefaultResourceTypes(); } /** * Initialize default resource types for module resource classes * * @return void */ public function initDefaultResourceTypes() { $basePath = $this-&gt;getBasePath(); $this-&gt;addResourceTypes(array( 'dbtable' =&gt; array( 'namespace' =&gt; 'Model_DbTable', 'path' =&gt; 'models/DbTable', ), 'mappers' =&gt; array( 'namespace' =&gt; 'Model_Mapper', 'path' =&gt; 'models/mappers', ), 'form' =&gt; array( 'namespace' =&gt; 'Form', 'path' =&gt; 'forms', ), 'model' =&gt; array( 'namespace' =&gt; 'Model', 'path' =&gt; 'models', ), 'plugin' =&gt; array( 'namespace' =&gt; 'Plugin', 'path' =&gt; 'plugins', ), 'service' =&gt; array( 'namespace' =&gt; 'Service', 'path' =&gt; 'services', ), 'viewhelper' =&gt; array( 'namespace' =&gt; 'View_Helper', 'path' =&gt; 'views/helpers', ), 'viewfilter' =&gt; array( 'namespace' =&gt; 'View_Filter', 'path' =&gt; 'views/filters', ), )); $this-&gt;setDefaultResourceType('model'); } } </code></pre> <p>To only bootstrap your application without running the front controller in tests/bootstrap.php:</p> <pre><code>&lt;?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') : 'testing')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); require_once 'Zend/Loader/Autoloader.php'; $config = array( APPLICATION_PATH . '/configs/application.ini' ); // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, array('config' =&gt; $config) ); $application-&gt;bootstrap(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload