Thursday, 14 February 2013

Starting with Zend


Zend Framework is the most popular and widely used framework of PHP. Zend provides many advantage over other framework. We can judge the its popularity by that thing, the most powerful CMS Magento is developed in Zend and used the Zend framework's library.

Zend is based on PHP5.0 and higher version. Its based on MVC (model-view-controller) Pattern. ZF is used PDO (PHP Data Object) and it also based on OOPS concept or we can say that it is based on a complete highly secure and demanded Pattern of current time.

So lets start with the Zend framework:

In my previous post you can see that how we can install Zend framework on our machine.
The link is Zend development: Installation of zend framework

Now we will see the MVC pattern in Zend:

Controller: We use the controller to handle the request of user and communicate between the view and models. Here I will saw you how you can make any controller.

First see the code given below:

<?php 
     class DemoController extends Zend_Controller_Action {
         
        public function init(){
          //some statement  
        }    

        public function indexAction(){
           //some statement
        }

     }
 ?>


Now let me explain what need to do and where need to do?

First thing make a file to controller and save it in the application/controllers folder with the same name as given the class name i.e. DemoController.php
In that the init function will call each time whenever we will make a object or call a function of controller.
For the functions, first we will give the name and then write the Action as shown in the code. The Action is required to tell the Zend library that it is an Action and by calling this this will call the corresponding view action page.

View: The view part is contains the HTML part which will view to the users. Here We put that data either from database or any other resource which will accessible or we can say visible to user whenever they will request to that part.

In Zend the view file is save by the extension of .phtml as it contains the PHP and HTML both code.
Each action will have its own view file and save in the folder that was the name of controller.

Example: We have make a controller by the name of TestController . Then we will make a folder with the name test in the view/script/ directory. and then make any .phtml file, with the same name of action that will present in the Test Controller, in this folder.

cheers ...

No comments:

Post a Comment