To support simplicity, possibility and cost effective of PHP

Getting started with Prado

Jan 15th, 2008 | By admin | Category: Prado framework

1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 3.50 out of 5)
Loading ... Loading ...

Prado is a rapid web application development framework that widely used nowadays by PHP coders. The framework at this moment is 3.1.1 show the maturity and stable. It provide coders with magnificent modules with beautiful ideas applied for MVC model.

The first noticeable thing in Prado is its control set which embrace the ASP.NET model of code behind. Any kind of HTML form element can be found in Praso as TWebControl object, for example, an HTML textbox is a <com:TTextBox> control. However, Prado even come in advanced compare to ASP.NET when provides ‘active’ controls that support Ajax. Prado also support custom control created by coder. Extending TWebControl or TTemplateControl, coders can create composite controls or new web control from scratch.

Then come Prado master layout which is very similar to ASP.NET master page. You can have many layout and in each page, choose which layout to display data. A default layout can be setup in application.xml file which is a web.config in ASP.NET.

More than just layouts, controls and all templating works, a wonderful idea in Prado is namespace. Namespace helps experience coders to quickly study the framework in a systematical way. By browsing the hierarchical class tree, coders can quickly find out what are the class he should use, what are its methods or properties and what is the parent class it is derived from.

Data manipulation is a pain in many programming model, especially before ORM is invented. While active record is support in ADODB long time ago, Prado support ActiveRecord and SqlMap, a customizable model of ORM. With SqlMap, you can create a custom mapper to map selected data to your class. For example, imagine you have table users and table roles in your DB. An user can have many roles thus in your code, you want to select user and all of the role he has. But how do you map many rows of data into one User object and all his roles into one array property called Roles ? SqlMap helps you do it in an XML file which contains your SQL Select query and the mapper.

Event driven programming is another nice feature that Prado provide. Embracing the model of web controls, Prado can wrap user request to define postback event, changed event to a page. So it is alway to served page is the postback page in a Prado web application. Control states are kept and any change of a control can be handled in its own changed event.

Not stop at that, a powerful configuration system allow you to add more Prado module into the application, such as caching module, multilingual module or user management module. Application wide parameters can also be configured as well as basic authentication based on page and user roles can be configured too, using a config.xml file.

I felt in love with Prado even after Zend framework became stable with version 1.0 release. The feeling is just more confident and stronger while making a website with Prado and taking any Zend component into used. You have a powerful framework to write quick and clean code plus a set of generic, powerful components from Zend framework library. For example, you can easily implement an Access control list in your Prado application with Zend_Acl or getting RSS feeds with Zend_Feed.

Enough for introduction, here are steps to make your first Prado website. You will be surprised how easy it is.

  1. Download Prado framework from www.pradosoft.com
  2. Extract folder framework into your web directory
  3. Now open command line and go to web root folder which is matched with something like http://localhost
    Execute this command to have Prado create folder structure for your first application
    php path/to/prado-cli.php -c .
  4. Now open your web browser and go to: http://locahost/first_prado. You will see the line: Welcome to PRADO! which come from /protected/pages/home.page
  5. Now create a php file home.php in the same home.page folder. Add this code to handle request to page home:
    class Home extends TPage{
    public function onLoad($params)
    {
    $this->label1.Text = 'Hello, world';
    }
    }
    
  6. If you refresh browser, there will be error as your page has an onLoad event handler which update a TLabel control called ‘label1′ while you have not added it to the page.
    Edit home.page to add the control:

    <com :TLabel ID="label1" />
    
  7. Now you can refresh your browser to see how the page is handled.
Tags: ,

6 comments
Leave a comment »

  1. does prado support oracle?

  2. Shouldn’t line 4 of the php code read

    $this->label1->Text = “Hello world!!”; // dot replaced with ->

  3. Thank Nightowl, i’ll update the post

  4. Yes, Prado supports Oracle since it works with PDO…

  5. I inherited prado starting to work in a new place, OMG! its the worst development environment ever!
    If you are trying to do anything beyond an amateur site, stay clear of prado, it is the single worst mistake you’ll ever make

  6. @pradohater It’s fine you don’t like Prado but I am not sure it’s any mistake embracing it as an working experience. I believe people with architect and OOP in mind love Prado. It’s the framework that allow you to write code in the clearest way, compare to many other welknown framework.

    Using Prado in production environment now is not a good option because the framework is almost not supported any more. Check Yii framework and you will know why.

Leave Comment