Step by step guide for Zend
Sorry for inconvenience; article is in raw state not yet finalized.
Introduction (Work in progress no to be published)
Using any framework is easy but applying that to real world application can be hard and time consuming task. People do get bits and pieces of the framework from google and other search engines but will not be able to find a concrete example that can help them lay out the ground they need for their start-up in practical application of that framework.
Background
When I started working in Zend framework I find the documentation is more inclined towards getting familiarity with different classes and other aspect of the framework but not a single concrete development example was presented that can bridge the gap between hello world example and real practical example. So I started to work on this article that will not only help you get familiar with Zend framework but will also help you create a web application from scratch to end.
Some good reference
There are some worth mentioning reference that people can look into, to enhance their knowledge and understanding
- Download ZFC_Study_Guide_v1.pdf – 2.56 MB
- Download ZendFramework1.6.pdf – 4.4 MB
- http://akrabat.com/zend-framework-tutorial-18/
- http://www.amazon.com/Zend-Framework-Action-Rob-Allen/dp/1933988320 (Highly recommended)
http://www.zend.com/en/webinar/Framework/webinar-ZF-Layout-20080319.flv
Some Nice working examples:-
Pr-requisites
Off-course you should have some familiarity with PHP. I am going to use ZendFramework-1.11.10 so I have uploaded the source as well to avoid any conflicts with future releases. You can also download the latest version here at http://www.zend.com/en/downloads/. You can also download Zend server and Studio for ease of use. Setting up Zend framework is easy so i am letting it up to you. In case I receive any queries related to setup I will surely add some clarification. I also consider that you are familiar with MVC model as well.
So what you have set up till now
You have Zend studio + Zend server and able to create a new project using Zend studio. Now I will discuss the directory structure.

-
application.ini purpose of this file is to contain all information related to configurations
- (Explained line by line
[production] //// All setting will related to production
phpSettings.display_startup_errors = 0 //// Startup error :setting it to 1 will display errors
phpSettings.display_errors = 0 //// display error :setting it to 1 will display errors
includePaths.library = APPLICATION_PATH “/../library” // Path for library
bootstrap.path = APPLICATION_PATH “/Bootstrap.php” // path for bootstrap file
bootstrap.class = “Bootstrap” // Class name for boot strap
appnamespace = “Application” // name space for application
resources.frontController.controllerDirectory = APPLICATION_PATH “/controllers” // directory for controllers
resources.frontController.params.displayExceptions = 0 // front controller is among one of the core things that a person need to understand
[staging : production] // having a colon “:” mean all the above configurations are inherited so you don’t need to explicitly set it here too.
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
-
Controller act as a bridge between Model and view. Zend claim that a “Zend_Controller_Front ” act as a main controller that calls other controller on different request.
Note:- I am still unable to find this zend controller front so it vague for me as of now.
-
Model:-
Will help you create some model classed to perform CRUD (Create Read update delete) options. We will look into details as we proceed.
-
View
Section contains different view that can be rendered on demand. I always wonder how different views can be merged together to create a full fledge web page.
-
BootStrap.php
Will help you put any boot time setting here.
-
Index.php
Index.php is the main file that will server all the request. Application environment is setup here and different paths are setup. Then a new “Zend_Application” object is created
<?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’) : ‘production’)); // Production here will tell to use production section in application.ini
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . ‘/../library’),
get_include_path(),
)));
/** Zend_Application */
require_once ‘Zend/Application.php’;
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . ‘/configs/application.ini’
);
$application->bootstrap()->run();
Ok if you run the following url http://localhost/ZendStepByStep/public/index.php you will be able to use the application.
Real work start now:-l
It seem really cool that now the app is running an you are able to access the URL but now you have accommodate it as per you needs and this is where you have to mold the things as per you need.
Let have a database configuration now:-
db.adapter = PDO_MYSQL (Php data objects)
db.config.host = localhost
db.config.username = root
db.config.password =
db.config.dbname = zsbs
-
Posted on December 22, 2011, in Zend. Bookmark the permalink. Leave a Comment.
Leave a Comment
Comments (0)