Showing posts with label Zend. Show all posts
Showing posts with label Zend. Show all posts

Monday, July 15, 2013

Create new controller on ZF

In this tutorial I'll explain how to create new controller and do more interesting stuffs. As I explained in previous post, for most important of controller, that requires directory with same name of controller and inside that, view pages with same name of all actions of controllers. But, this is automatically managed by ZF command line tool. And in Netbeans IDE there is more good interface for executing commands

- in Netbeans project panel --Right Click on project > Zend > Run Command... and interface will be open.


  • First parameter is "Filter": That similar to search particular command from all command list.
  • Matching Tasks: This will show you commands matching your query entered in Filter textbox. Select proper command from list. There is text area below list of commands, it'll show you description.
  • Enter required parameters in "Parameters" textbox.
  • At very bottom, there is "commad", it'll show you final output command. 
  • and press Run to execute command.
  • For example, I've created controller named "info".










[controller]

[view]


As Shown above both images, you can see new created controller: "InfoController.php" and for that controller there is "info" directory with .phtml files of actions of controller.

Now, let's modify Info Controller:
- Remove content of index.phhtml and edit indexAction in Controller.








In any controller there is init() and indexAction() as by default. You can create as many functions you want. When any controller executes init() method always executes first, no matter which action you are executing from that controller.

Now, Lets create another action in info controller with its view:


and add some message in anotherAction() function...

and execute...


That's it. This is enough to get started with ZF Controllers.

Understanding Directory Structure in ZF

When we create new project in Zend, it creates directory structure for us. On right side image, full directory structure of ZF application is shown.

This structure has four main area, application, library, public, and tests.

Application Directory: Is responsible for holding our application-specific files such as configs, controllers, models, and views. These are basic in any zend framework application,  in some zf application there is modules directory, holds different modules required for application. So, This application directory contains main MVC files.

Library directory: Is responsible for holding our supporting classes that not come into the scope of model. Inside library, we have the zend directory that contains the ZF source files.

Test directory: Stores our tests for our application.

Public directory: Is responsible for holding all of our publicly accessible assets such as images,CSS, and JavaScript.


Bootstraping [Bootstrap.php]:  This refers to the process of application initialization where we configure, and startup, the MVC process when someone requests a page.

The Index file [index.php]: This file is created under public directory, which is the main entry point for all of the requests to our application. This file points to application, library directory and application environment of application.

.htaccess file: This is important file in application, that rewrites rules for routing.

Application Configuration [application.ini]: This is most important for zf application. This is heart of application. Because, it contains all configurations about our application like php_errors, database connection, & path application, controller, library directory and all routing mechanisms are written here.



Starting New Zend Framework Project

Hello, I'm back with new Zend Framework Tutorials. Go through these given links before directly starting from this tutorial:


In, this tutorial I'll explain how to create new Zend Project on your server with NetBeans IDE. Follow the steps as show in image below:
    [Image 1]

    [Image 2]



















[Image 3]

    [Image 4]


    


























[Image 5]


If you see directory structure like image 5, then congratulations...!!! your  Zend Project is ready to start.

Other ways to create project:
Zend Framework having powerful command line interface for doing work more easily. In Zend framework library you downloaded, there is "bin" folder contains zf.sh and zf.bat files.
- First go to the directory where you want to create your project.
- path-to-bin/zf.bat  create  project  project-name

Now, I created virtual-host named http://zf2-local.com.  This virtual host points to my public folder not root folder of project.




That's it, if you are able to see this type of page, then your created project works very well.



Sunday, October 7, 2012

Which framework is best for you ?

List of most popular frameworks :

There are many other frameworks available, but these are most widely adopted by developers.

Each of these frameworks is built in PHP language, but they differ in their methods and libraries.


Each of these frameworks has been released as open source projects, which means that a lot of development work relies on community support. Tracking bugs, writing supporting documentations, and providing general support are tasks that involve developers like you.




ZEND FRAMEWORK

Zend Framework was arguably the first framework to be built for PHP. Its corporate sponsor, Zend Technologies, has a long history with the PHP language itself; its founders include two of the original authors of PHP, Andi Gutmans and Zeev Suraski. Much of what has made PHP one of the most popular web programming languages started with Zend Technologies and its contributions to the language. That being said, no wonder Zend Framework has had early success and continues to be a major player in the PHP frameworks market.

In terms of community support, Zend Framework has probably the largest online following of any of the PHP frameworks. Its documentation is extensive and thorough, and unofficial blogs and forums make it possible to get online support for just about any question. Code submissions to the core are passed through rigorous testing methods, which makes Zend Framework an incredibly robust framework. However, Zend Framework is much more of a large set of libraries than a lightweight MVC framework. For instance, its main library folder is almost 16MB, more than three times the size of Cake’s libraries. Getting Zend Framework off the ground requires much more customization and configuration, whereas Cake has adopted more of the “convention over configuration” paradigm. You could likely use Zend Framework with just about any PHP project, which I'll demonstrate in   tutorials.

Zend Framework has no single development paradigm like Cake, CodeIgniter, and
Symfony, and that appeals to many developers. Patterns like MVC are therefore possible in Zend Framework, but these require you to manually write configuration methods, which are automatically built into Cake and other frameworks. Cake is certainly ahead of Zend Framework in how the framework cuts down the amount of code needed to extend it. Learning Zend Framework is generally more time-consuming than learning Cake, mostly because of the design of the framework. Getting an MVC variant of Zend Framework off the ground is usually more difficult for a beginner than Symfony, not to mention Cake.

True, Zend Framework is more well known than Cake in most PHP circles; it’s the veteran on the team, if you will. But Cake is proving to be more like the rising star that moves faster and is strategically sounder. Given Cake’s effective implementation of the MVC structure and its structural design, it will likely continue to attract former Zend Framework developers and remain the top player in the PHP frameworks arena.



CODEIGNITER


CodeIgniter’s community is relatively small when compared to CakePHP but does have a good support network online. Its user guide (www.codeigniter.com/user_guide) is well designed and has a nice layout for navigating through the table of contents. Many of the concepts used by Cake are also used by CodeIgniter, such as the MVC structure, helpers, routing, scaffolding, and caching. The support network is great, with a forum that boasts more than 66,000 topics and more than 400,000 posts. However, a lot of the topics there aren’t directly related to code development issues like Cake’s discussion group. In a sense, CodeIgniter’s forums and wiki are more like combining Cake’s discussion group, Bakery, and CakeForge. The number of websites built on CodeIgniter is smaller than that for Cake, but CodeIgniter is off to a good start and will likely become a more popular framework in the future.


Starting a CodeIgniter application takes less time than setting up a Cake application; however, some configuration methods that come preinstalled with Cake are left out with CodeIgniter. For example, setting up routes to behave like they do in Cake will require that you manually write an .htaccess file to pass paths through a similar routing engine. By default, CodeIgniter is more lightweight than Cake, which is one of its chief selling points. However, as you expand your CodeIgniter application, expect to have to perform an extra step here or there to achieve the same functionality you get from Cake.


The MVC structure in CodeIgniter is similar to Cake’s. Because of this, the general process of creating models, views, and controllers is nearly identical to what you learn when building Cake applications. Aside from minor differences in passing data around the application and naming conventions, running CodeIgniter is largely the same experience as in Cake. However, where Cake wins is with its powerful core classes, helpers, routes, and data-handling methods. The available resources and built-in functionality are more robust in Cake and, frankly, more cohesive. In other words, Cake developers will probably think they have taken a step backward when fully immersing themselves in CodeIgniter, though they will undoubtedly think they are in familiar territory. That’s not to say that CodeIgniter isn’t already a fabulous framework; it’s just that it separates methods into its several resources less effectively than Cake. In a nutshell, the Cake paradigm is more about making the model fat and spreading out the various methods; CodeIgniter makes for very large controllers.


SYMFONY

Symfony entered the PHP frameworks arena early on and has remained popular. Its community is also large with developers groups, forums, a chat room, a wiki, and more. All of the main links to these various online groups and sites are available on Symfony’s community web page (www.symfony-project.com/community).


After you have successfully begun a Symfony application, you will need to initialize your data source connections using the command line as well as perform other setup tasks. Generating the scaffolding is also done in the console, but the final result is similar to Cake’s scaffolding. Building models is primarily done using YAML-based configurations together with the symfony console script. If you prefer YAML to JSON or XML for configuring your database schema, then Symfony will probably suit you well. Cake really doesn’t compare in this regard because its methods for connecting to a data source don’t involve the command line (even though you can use Bake to write your database.php configuration file and build models).

When extending the Symfony application to take on more methods, many of the same concepts that make Cake effective are used. The learning curve is steeper when going from Cake to Symfony, mainly because the benefits Symfony offers are usually found in its command-line interface. However, Symfony users shouldn’t find learning Cake all that difficult. It may take some getting used to running fewer commands in the console, but on the whole, you shouldn’t have to perform any more steps to build your Cake applications than you would expect for a Symfony application.




CAKEPHP

Duplication throughout the community is kept to a minimum, so expect to be directed to a thread or blog post that someone has already used to address the same topic when asking a question or requesting support. You will also probably sense a feeling of perfectionism in the community. What I mean by that is this—the Cake Software Foundation, which manages Cake’s development, could have easily taken shortcuts when developing the framework. Compared to other frameworks, Cake would already be considered a version 3.0 or 4.0, but it’s currently at 1.2. This is due more to really tightening up the framework rather than cooking up something fast that could perform a large plethora of methods. The result of this strategy is that Cake really is more robust, mature, and well written than it otherwise would be, and you can count on it maintaining its robustness as it takes on more fancy methods.



Then "Which framework is right for me ?"

In each framework, you might notice powerful features than other framework, but selection of framework is always depends on which type of project you want to develop. Because, every framework has its own power to drive a site properly. In all framework powered sites, 60-65% site powered by Zend Framework, because of its beautiful and awesomeness.

To answer the question fully though, we really have to examine why we use a framework. Aside from the “two choices” scenario described above, programmers use a framework to simplify application development by providing much of the common code. A good framework will also enforce some structure on the code. However,  be wary of any framework that enforces rigid style conventions that you do not already adhere to. Your chosen framework should be flexible enough to adapt to the style and needs of your project.


The ultimate goal when selecting a framework, is to find one that allows you to work in a way that is natural to you, provides you the services that are most common to your application and allows you to concentrate on building the code business logic of your application.


To be fair though, the right framework for you is the one that lets you be productive quickest and leverage your new skills the longest.