0
votes

I am trying to figure out how autoloading function with Zend Framework.

questions:

1 - say I want to add to my application/ folder a folder called x/ containing a class named Foo.php. How do I get it auto-loaded when I do new Foo() from a controller? And then how should I name The class Foo? Is "Foo" alright or should I use the name "Application_X_Foo"?

2 - whats this story with $autoloader->registerNamespace('My_')? I mean where should the classes in the namespace My_ live?

Thanks

1

1 Answers

1
votes

1.- For application specific classes you should use Application_Model_Foo as the class name and have it located under "application/models/Foo.php"

2.- If you want to add other namespaces/libraries to your project you could add these under the library/ folder. In the "My_" namespace case you should add it to "library/My" folder.

Here, you can have a look to the directory structure of a basic Zend Framework project:

|-- application
|   |-- Bootstrap.php
|   |-- configs
|   |   `-- application.ini
|   |-- controllers
|   |   |-- ErrorController.php
|   |   `-- IndexController.php
|   |-- models
|   `-- views
|       |-- helpers
|       `-- scripts
|           |-- error
|           |   `-- error.phtml
|           `-- index
|               `-- index.phtml
|-- library
|-- public
|   |-- .htaccess
|   `-- index.php
`-- tests
    |-- application
    |   `-- bootstrap.php
    |-- library
    |   `-- bootstrap.php
    `-- phpunit.xml

By the way i would recomend you to have a look to the Zend Framework Quick Start guide: http://framework.zend.com/manual/en/learning.quickstart.html