Wednesday, 16 October 2013

Zend Framework Controller Help

1. CSS from the Controller:

Add the css file from the Controller:


Use the above code in the controller's action to add the particular css file for the particular action.
2. Javascript from the controller:
Add the javascript file from the controller:

Use the above code in the controller's action to add the particular JS file for the particular action.

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:

     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 ...

Wednesday, 13 February 2013

Design Pattern in PHP

Design PatternThe design pattern is an architecture to make the project robust and fast. In design pattern, the structure of the programmer is be in such a way by which we can make the code reusable, objects reusable, and the make the code simplest and optimized.

Design pattern is basically five types:

Singleton Pattern: This pattern has the concept of making a single object of any class in whole of the project and we use that single object instance anywhere.
                  The basic concept behind it is the create a single instance of a class and this object is accessible at any where in the project.


    class test() {
      public static $instance = null;
       public static function getInstance(){
          if(NULL == self::$instance){
               self::$instance = new test();
           return self::$instance;

Factory Pattern: This pattern is used in business logic side. We will have those function and functionality which we can use multiple times in the project.
             It means we have such function in the Factory that have the common functionality and will be reusable. This pattern basically used to reduce the code and make the code quick changeable.

Example: if we want to make a calculator or like such any functionality then we will create a class and different methods in which we will pass only parameters and the corresponding functionality will perform. and we can use this class in other projects also.

Other Patterns are: 

Abstract Patterns.
Decorator Pattern: The decorator pattern is a structural design pattern which enables us to add new or additional behavior to an object during run time, depending on the situation.   
Strategy Design Pattern.