web developing
11 Aug
When someone starts with the learning of a framework, first he begins to read various articles to understand the basic rules to work with.
There are a lot of tutorials how exactly to start, and there is also an official quick start guide, but beside this there are too much advices how should you directory layout look like.
For me the following directory layout is working well. I don’t remember exactly where I’ve found it, but I think many people use it.
Almost half of the sources “how to start” recommend all of the initialization should be in index.php in the public folder. In fact all the logic of the public/private folders is that we don’t like to show anything on the web, and that’s why index.php contains only the following peace of code (it’s recommended to leave the file open from the ?> closing tag):
<?php
require '../application/bootstrap.php';
Anything else, all the initialization is in bootstrap.php:
error_reporting (E_ALL | E_STRICT);
ini_set (‘display_startup_errors’, 1);
ini_set (‘display_errors’, 1);
set_include_path (‘../library’ . PATH_SEPARATOR . get_include_path());
require_once “Zend/Loader.php”;
Zend_Loader::registerAutoload();
$front = Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
$front->setControllerDirectory(array(‘default’ => ‘../application/content/controllers’,
‘admin’ => ‘../application/admin/controllers’));
$front->dispatch();
We set the error reporting to be ON, which si good when you develop any application and to collect all error messages. Than add the library folder in the include path with that line of code:
set_include_path(‘../library’ . PATH_SEPARATOR . get_include_path());
Next step is to start the __autoload functionality built in Zend Framework:
require_once “Zend/Loader.php”;
Zend_Loader::registerAutoload();
Finally start the front controller which implements the singleton pattern and point to the two main directories – admin and content. I used them for administration panel and front end, but you can used as many as you application needs:
$front->setControllerDirectory(array('default' => '../application/content/controllers',
'admin' => '../application/admin/controllers'));
Related posts:
8 Responses for "Zend Framework – quick tutorial (part 2)"
Hi,
Thank you very much for this information. It helped me a lot.
Thanks again,
Jyotsna.
Good article, adding it to my bookmarks!
Great article, adding it to my bookmarks!
Just read some other comments on your blog, and I agree with the general impression, your doing a great job!
Your writing style is quite a good role model for me – I have recently started my own blog and I am really struggling to write articles!
I was wondering if you could set up some sort of system so when your publish a new article, i get emailed to alert me? Or something like that.
I’m new with Zend after several years of programming php and several classes. I’m having troubles setting up Zend Framework 1.10.0 on my local machine. Has there been some changes in the set up or am I doing things wrong? I’ve set up the folder structure just like the structure on this post but I’ll get the following message:
Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /Users/crispijn/Sites/Zend/Loader.php on line 223
Fatal error: Uncaught exception ‘Zend_Controller_Dispatcher_Exception’ with message ‘Invalid controller specified (index)’ in /Users/crispijn/Sites/Zend/Controller/Dispatcher/Standard.php:242 Stack trace: #0 /Users/crispijn/Sites/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /Users/crispijn/Sites/bootstrap.php(20): Zend_Controller_Front->dispatch() #2 /Users/crispijn/Sites/index.php(10): require(‘/Users/crispijn…’) #3 {main} thrown in /Users/crispijn/Sites/Zend/Controller/Dispatcher/Standard.php on line 242
Maybe it’s time to update your post and make us happy again! I looked arround your site and I think it’s great to have such a great resource for a framework! Keep up the good work!
Actually that post was a bit earlier than the 1.8 version of Zend Framework where Zend_Loader_Autoloader was introduced. In fact I described that in another post here. Thanks for the advice I’ll check my source again!
Leave a reply