Wednesday, May 12, 2010

Using Yii PHP framework on Netbeans 6.8

A few days ago I downloaded Yii PHP framework 1.1.2. I played around with the manual quickly to check if I can use any of the features in my future project. Yes I found Yii to be a very interesting PHP framework. The developers really did a nice job and I recommend it.

I quickly started a mock up project to see if I can use the features and the results were awesome. My system configuration is a WAMP using Netbean 6.8 IDE.

The application

Our application is a simple online shopping system.  It will be used to keep customer data for a small door to door delivery grocery shop called Matombo.  The idea is a customer registers on the company’s website. After registering the customer can order groceries online on the shop’s website. The shop then delivers the order. The order can be delivered to any address which can be serviced by the shop. For simplicity we won’t touch the payment module. The idea was borrowed from a few Zimbabwean online shops for sending groceries back home for the people in the Diaspora. Please see these website for a live system using the idea stated.

In this post and more posts to follow I will show you how I achieved such a website.

Setting up

I will put the Netbeans project in a seperate folder and will use the IDE’s capabilities to publish the files to the htdocs directory under Apache. So first we create the application using the yiic tool which is a command line tool from Yii.

  1. Start->run->cmd
  2. path=”c:\php” [put the path to your PHP directory if it’s not in system path otherwise skip this part if it’s in your path already]
  3. cd C:\JDeveloper\netbeanswork [this is the directory where I have my netbeans projects]
  4. C:\JDeveloper\yii-1.1.2.r2086\framework\yiic webapp Matombo [this will create an application called Matombo on the folder “C:\JDeveloper\netbeanswork”]

Your application will be ready and can be used from here. Now in Netbeans 6.8 IDE we create a new PHP project as follows.

ScreenHunter_01 May. 12 21.57

 

Next add the source files as illustrated below.

ScreenHunter_02 May. 12 22.01

Sources folder refer to the folder with the application which was created by the yiic tool. For project name I prefer the default one and for this application Netbeans picked Matombo.

On the run configuration step we have to setup the application URL and web root folder as illustrated below.

ScreenHunter_03 May. 12 22.11

For this application I had to move the files from the project directory to the web root.

Run As: I put the local website.

Project URL:  Do not forget to put the listening port for your application, on my Apache server it is on 3569.

Copy files to sources folder: Tick this checkbox if you have a setup like mine for moving files from one folder to the other. Put the web root folder in the Copy to folder textbox.

Click finish and the IDE will have the project loaded. I like to set the project as the main project in the IDE. This has an advantage that clicking the run button on the toolbar will run this project.

Now you have to add the includes to the IDE so that you are able to use the auto complete for the IDE.

On the project folder in the IDE right click the folder and move to Project Properties. On the dialog window move to the “PHP include files” option and add the Yii framework folder. At this point your IDE can use auto complete.

Test the auto complete by opening the PHP files in the protected->models folder and just try typing in something like

$this->

inside any function and see this pretty IDE showing the auto complete feature.

Click on the run button and the IDE runs your application.

 

On my next post we setup the database and use gii widget to create models and CRUD.

5 comments:

  1. Thanks you very much! This article very important for me! :)

    ReplyDelete
  2. THANKS UR GREAT !! This helped a LOT !!

    ReplyDelete
  3. so good! Great thanks Man!

    ReplyDelete
  4. tx...a looootttttt man!!!!

    ReplyDelete
  5. Codelobster PHP Edition has great wizard for Yii installation and development too.

    ReplyDelete