by
faheem on June 11th, 2010
I have been working in yii for the last two months or so. Initially when I started working in it, I thought that it’s an amzing framework, quite easy, flexible and fast. I found my mouth open when I created my first appliction using yiic and I said wohooo, its kinda real fun. But working for sometime things got a bit hard for me. I was unable to understand how to make relationships and then fetch data from related tables, but with the passage of time and after reading the documentation it gave me lots of surprises.
I don’t know what my opinion will be about yii in future, but currently I find it quite helpful and interesting. It will be worth mentioning here that before working in yii, I had worked in different frameworks like Zend Framework, CakePhp and even for some time in RoR. I have nearly two years of Zend Framework experience, and when I was doing my first project in Zend, I was kinda fall in love with it. Many people complain about Zend complaxity but I would recomand it for enterprise level application as it provides nearly everything that a large scale application needs.
This article has nothing to do with the comparsion, its purely about yii introduction and my experience with it, so I m not gonna give pros and cons of the frameworks that I have used so far. Lets leave it for future discussion.
The best thing that come to my mind when I think about yii is its installation. It cannot be simple then this, download yii from http://www.yiiframework.com and extract where you like it to be, like your application root. I suppose you keep it in /var/www/ on linux. Once you extract it open your browser and write as follows for checking system requirements.
http://localhost/yii/requirements/
Your system must pass certain tests like php version should be 5.1.0 or greater etc. if not some of your configuration don’t pass some of yii functionality will not work accordingly.
Once successfully install next step is to create your application, but before devling into the details of how to create your first application, I will suggest you to go through demo application in path/to/yii/demos/. The are no doubt good point to start with.
Once you decide that its time to create your first application, go to terminal/command prompt and execute the following command.
yiic webapp path/to/root/app_name
The above line will create complete directory structure, like all your contorllers, models and views directories etc. The line however may not work in some conditions like
If path to your php.exe is not set(mostly in windows)
You can freely ask your questions if you stuck somewhere. I will be glad to hear you.
Once you successfully created your application, then comes the time to wit your hands with the code and the first place where I will emphesis to make changes is “ your_app/protected/config/main.php” file. Here you can make database configuration; already done, you will need to comment out code that you don’t need, give host, database user and database information(if you like to use mysql instead of postgrase).
There are lots of good things about yii, but the one I would like to mention in this post is “gii”. GUI that give you ability to create controllers, models, view and even CRUD. For “gii” you will need to add the following code in your “path/to/your_app/protected/config/main.php”.
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'12345',
),
),
Now if you write http://localhost/your_app/index.php?r=gii, you will see a page asking you to login. Once loging in you can use “gii” GUI to create controllers, models etc.
Just try yii and let me know whether you find it interesting or not.
Your queries will be welcome.
Oh come on, I know that yii cannot be covered in one page article so lets leave discussion open.
by
faheem on May 15th, 2010
It has been long since written on my blog, how lazy I m, why not get some treatment form the people around me. Why not developers all around chop ma head and screw me up for being so lazy. But mind you don’t try this, coz I belong to the area where people are treated so hard that nobody can even think of. Now don’t ask me where do I belong to.
Its Saturday, off, but I m on and m in great mode. I don’t know why m I feelen so happy though we lost our semi last night. I’m juz chilling.
Gaad daym, what I am written on my technical blog, it shon’t be like this. So lemme move to the topic and put aside this mess and hassles.
Since yesterday I’m try to get this work for me, I’s unable yesterday, but today it really worked for me. Nothing else but COM did the job for me. I m going to share this code with you and m sure that it will serve you lot. Don’t tell anyone that I found this code on the web otherwise I will punch you down and kick you skinny ass.
The code here will read contents form .doc, save those to .txt file and then read contents from that txt file. Here is the code.
$word = new COM("word.application") or die("Unable to instantiate Word");
$word->Documents->Open($file);
$new_filename = substr($file,0,-4) . ".txt";
// the '2' parameter specifies saving in txt format
$word->Documents[1]->SaveAs($new_filename,2);
$word->Documents[1]->Close(false);
$word->Quit();
//$word->Release();
$word = NULL;
unset($word);
$fh = fopen($new_filename, 'r');
// this is where we exit Hell
$res = fread($fh, filesize($new_filename));
fclose($fh);
unlink($new_filename);
echo $res;
So what we’re doing here.
Instantiate COM, open file, save content as .txt file, open .text file and get contents. That’s it.
Juz give it a try and you will find it quite helpful.
by
faheem on February 13th, 2010
You may have heard about FPDF, TCPDF. These are used to generate PDF document in PHP. But very few of you may have heard about LiveDocx, can be found here http://www.livedocx.com/. The most cool news I’m going to tell you that Zend Framework 1.10.0 provides clean and simple interface to LiveDocx API. LiveDocx is soap based service. If you are interested more in LiveDocx, following the link I’ve already provided you.
In this article I am gonna tell you how to create word processing documents and PDF using Zend_Service_LiveDocx. I am sure you will find it very helpful.
You can create you desired document by following these two steps.
1) Create template file
2) Fetch records from your database, as you usually do and assigned them to the template.
1) Creating template file
You can create your template file using Microsoft Word, openOffice and save then as .doc or docx or .rtf format. Keep in mind that creating template file in MS Word and openOffice may differ. In my example I am using Microsoft Word.
Open Microsoft word and create new document.
Before creating the document, I want to show you the resultant template that I’ve created for this example is bellow.

The sign “I” at the stat and end means that I want to repeat this block many time.
And the result file, populated with the data will like this.

Now as you have opened and created document, move forward and insert table as I have inserted in the above example. Put [ in the first row and then click “Insert” in you menu bar and click “Field”. This will open up the following dialog.

Select “Mail Merge” from the “Categories” dropdown and select “MergeField” as show in the following screenshot.

in the “Field name” textbox write “pkey” as show in the following diagram.

Insert all your “MergeField” in the document and create the document you desired. Now if you want to repeat entire block you’ve created or part of it, click at the beginning of that block and select “Insert” form your menu bar and click “Bookmark” as shown in the following diagram.

This will open the following dialog.

I’ve written “blockstart_issue” in the “Bookmark name” text field and pressed “Add” button. Now go to the end of the document or the block you want to repeat, and insert another bookmark using the same method discussed above. But this time the name must be “blockend_issue”. The start bookmark must be like “blockstart_example” and end bookmark should be named “blockend_example”. You can place any text in place of “example” as I’ve put “issue” in my case.
Now as you have defined your template, save it at appropriate place.
2) Fetch records from you database, as we usually do and assigned them to the template.
You have successfully created template file, now its time to instantiate Zend_Service_LiveDocx in your controller as
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername("username")
->setPassword("password");
Keep in mind that Zend_Service_LiveDocx is based on soap service, so you will need to get register at http://www.livedocx.com/. When you register with the username and password you will need to set your username and password in place of username and password in theabove two lines.
Next step is to assign values to “MergeField”, you defined while creating your template file. This can simply be done as
$phpLiveDocx->assign(‘pkey’,’TC-4’);
But as I have put bookmarks at the start and end of the entire block, it means that I want that the entire block be repeated for me. So I will first create an associative array as
$issuesData = array(
array (
‘pkey’ => ‘TC-6’,
‘summary’ => ‘Pagination not working in administration area’,
‘created’ => ‘2010/2/12’
……….
…….
)
array (
‘pkey’ => ‘TC-7’,
‘summary’ => ‘Validation not working’,
‘created’ => ‘2010/2/12’
……….
…….
)
);
And now assign this associative array as
$phpLiveDocx->assign(‘issue’, $issuesData);
Here issue is what we defined at the time of putting merge fileds “blockstart_issue” and “blockend_issue”
When you assign data to your “MergeField”, you will need to retrieve the desired document by the following statements.
$document = $phpLiveDocx->retrieveDocument('doc');
unset($phpLiveDocx);
Once the document is generated using the above statement, defined appropriate header and print the created document. I’m using the following statement.
header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=report.doc");
print $document;
Note: Bookmark will not be visible when you put them in your template. In order to view them select “Tools” from menu bar and then “Options”. Check bookmark checkbox in the view tab in the popup dialog.
by
faheem on February 1st, 2010
10 minutes ago I downloaded Zend Framework’s latest version 1.10.0. I was using 1.7.8 for developing open source bug tracking application.
I was already aware of the change made to autoloader, but I didn’t make auotloader work for me in the first attempt. I was unable to load my models and forms.
I was using the following code for autoloading my models, forms and zend framework components.
require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();
and then setting my include path as
set_include_path(
APPLICATION_PATH . '../../../library'
. PATH_SEPARATOR . APPLICATION_PATH . '/../application/models'
. PATH_SEPARATOR . APPLICATION_PATH . '/../application/forms'
. PATH_SEPARATOR . get_include_path()
);
When I replace loader code with the following code
require_once "Zend/Loader/Autoloader.php";
$autoloader = Zend_Loader_Autoloader::getInstance();
I encounter an exception saying that loader is unable to load my models. Googling for a bit of time I found the solution.
Actually Zend_Loader_Autoloader is a namespace-based autoloader. By default, it only registers the Zend_ and ZendX_ namespaces.
so it won’t load classes from your own directories.
To force loader to load your classes you will need to write the following statement right after the initialization of your loader.
$autoloader->setFallbackAutoloader(true);
Including this statment will not only load your model, but also pear packages if used in your code. I wonder you wont be able to use pear packages without writting this statement.
Another exception that I wasn’t expecting was file decorator exception. I’m using Zend_From_File for uplaoding files. As soon as I browse my page using Zend_From_File component, i was told that i am not uisng file decorator, I was setting decorator to my file element as
$file1->setDecorators(array(
'viewHelper',
array('Description', array('tag'=>'', 'escape'=>false)),
array(array('data'=>'HtmlTag'),
array('tag'=>'td', 'valign'=>'top', 'style'=> 'background-color:#ffffff;text-align:left')),
array('Label', array('tag'=>'td')),
array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
));
After googling my issue I found that I will need to enclude Zend_Form_Decorator_File with file elements. The changes I made are
$file1->setDecorators(array(
'File',
array('Description', array('tag'=>'', 'escape'=>false)),
array(array('data'=>'HtmlTag'),
array('tag'=>'td', 'valign'=>'top', 'style'=> 'background-color:#ffffff;text-align:left')),
array('Label', array('tag'=>'td')),
array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
));
By comparing the codes above you will find that I have only replaced “viewHelper” with “File”.
by
faheem on January 15th, 2010
Ahmad Faraz was born in Kohat in 1931. He was considered one of the greatest modern Urdu poets of the last century . He did masters in Urdu and Persian from University of Peshawar. He was awarded “Sitara-i-Imtiaz” for his work in literature/Urdu Poetry.
To pay tribute to his work I would like to share a piece from his poetry.
تم اپنے عقیدوں کے نیزے ہر دل میں اتارے جاتے ہو
ہم لوگ محبت والے ہیں، تم خنجر کیوں لہراتے ہو
اس شہر میں نغمے بہنے دو، اس شہر میں ہم کو رہنے دو
ہم پالن ہار ہیں پھولوں کے، ہم خوشبو کے رکھوالے ہیں
تم کس کا لہو پینے آئے، ہم پیار سکھانے والے ہیں
اس شہر میں پھر کیا دیکھوگے، جب حرف یہاں مرجائےگا
جب تیغ سے لے کٹ جائے گی، جب شعر سفر کرجائےگا
جب قتل ہوا سب سازوں کا، جب کال پڑا آوازوں کا
جب شہر کھنڈر بن جائے گا، پھر کس پر سنگ اٹھاؤ گے
اپنے چہرے آئینوں میں، جب دیکھوگے، ڈر جاؤ گے
by
faheem on January 10th, 2010
With each passing day
I plan something new
I wish something new
Don’t care about people outside
Try to get and to make more inside
Don’t think who’s suffering
who’s crying
and coz of hunger who’s dying
I don’t care, children in the streets barefoot
what I care is how much am looking nice and cute
by
faheem on September 17th, 2009
I worked on enterprise level application for one year using Eclipse, Php Designer, and Dreamweaver. We were using Eclipse for checking in and out (updating and committing)
When I joined the team, configuration was already in place in the Eclipse, so I never intend to make configuration. Whenever configuration needed, Team lead was up to the task and was responsible for the entire configuration. I came across new terms like SVN, Commit, and Update for the first time as I was using cute ftp for uploading and downloading files from server before.
Here our job was to write code, complete tasks and commit them using our team lead system. First job in the morning was to update the change as some developers were making change to our project in United States. Our team lead system went of order few times during this period, but we were always looking toward him for the configuration. I remember that once he configured everything on my system, but I never intended to look how everything are done.
Today I found myself stuck in the middle. As I’m going to start working on new project, I tried to do the entire configuration myself.
Believe I was having no clue how to do it. Thanks to some nice soul out there on the internet who have posted the entire step by step procedure. I am going to write those steps for you.
Import project in Eclipse
1. File >> New >> Project >> SVN >> Checkout projects from SVN
2. Next
3. Create a new repository location
4. Next
5. Enter URL as
http://yourserver.com/alpa_proj
6. Next
7. Select the directory
8. Next
9. Choose: checkout as project configured using the New Project Wizard
10. Finish
by
faheem on August 27th, 2009
Note: This article was written in 2008, when I was working in small firm. Publishing it again here for newbies.
After working for about one year in website development industry of Pakistan I’ve realized a very serious issue. This may be happening in other countries as well, as I haven’t had worked with international organization, especially professionals.
The problem is mixing presentational logic with business logic. In simple words I would say maxing HTML with server scripting language like php, asp, coldfusion etc.
Here I would appreciate Microsoft professionals who have done tremendous job by developing Asp.net language. The way they have separated asp.net and html code from C# and VB.NET code is fabulous. However I would like to mention that in the beginning-in early versions of ASP.NET-the problem was there. However with the passage of time and introducing newer and more mature versions like ASP.NET 2.0 they have addressed lots of issues.
Before going into the details of problem mentioned above I would also like to comment about some companies who are providing open source solutions for languages like PHP etc. The contribution made by oscommerce (having the above drawback), zencart(I haven’t studied but heard that it is a bit mature shopping cart solution than oscommerce) and joomla(very nice and more mature content management system) to php cannot be ignored.
The most important contribution is made by those who have developed frameworks(MVC’s) like Zend, Symfony, cakePhp, mojave(lacking documentation and community support) etc. One cannot imagine how worthy and brilliant job they have done and how easier they have made work for lazy professionals like me.
Two months back I was introduced to mojavi by our company senior web developer. In the first few days I was exhausted and bored. However after developing a simple login application in mojavi I found it quite helpful. But things didn’t move forward coz of lacking documentation and community support.
I stopped working in mojavi but the virus of working in frameworks sneak in my heart and I started googling different frameworks.
Next few days I studied cakePhp, symfony and then zend, red their documentation, browse their community support sites and forums and also red articles about their differences.
Finally and luckily I selected Zend framework-This was because of small configuration overhead of zend framework than other frameworks.
After working in zend MVC I realized how easier it is to make a web application and how easy it is to extend and maintain existing one.
Now let me discuss the real problem which has made me sick since last few days.
After joining new organization 6 days back I was assigned a project for modification. The project was constructed in oscommerce. Boss was expecting that I would finish some small modification in few hours but I trapped in the middle and was unable to browser where modification needs to be made.
When boss arrived and asked me about the modification I was having no idea what to say and I felt a bit shy at that time. After telling him that I haven’t completed the modification he was a bit shocked and worried because he might be thinking that I was not a right person for the post I had been hired. He took me to his office and asked me about projects I had previously worked on. After showing him my projects he got satisfied but still I could see uncertainty in his eyes.
Why all this happened and why I trapped in the middle will I think clear the problem I have mentioned in the beginning..
As I have already mentioned that project was constructed in oscommerce so those how know or have worked in oscommerce will better understand the way oscommerce has been developed. Although they have separated php code form html up to some extent, however it is not as mature as joomla content management system or model view controller frameworks.
Well, oscommerce was not a big obstacle. The more irritating thing was the way previous programmer had implemented and constructed the pages. After working in office for about 10 hours I managed to complete some modifications but not entire.
When I came home, installed oscommerce and started doing the same modifications it took me minutes to complete them.
So I took some deep breathes and started thinking about whom to be blamed. But after thinking for about two hours I realized that no one could be blamed because client needs their projects soon, so developers only think about the construction not about what will happen in future if he himself or someone else try to extend or modify the project.
Lot of website have been made in similar scenarios and situations.
So as a professional one needs to be very careful while modifying the project.
Although professional developed application based on the client recommendations however I think we professional should think seriously about the future extensions and maintenance and try to make application both client and professional friendly.
by
faheem on August 18th, 2009
Ruby on rail is used for web application development.
Ruby is object oriented language.
Rail is framework that uses Ruby language to develop robust and scalable web application.
Ruby on rail installation is simple, newbie however find it a bit tricky first.
Here in this article I am going to tell you how can Ruby on rails be installed in windows XP.
1. Download latest version of Ruby from http://rubyforge.org/projects/rubyinstaller/
2. after the installation double click the exe file. this will start setup wizard which will guide you to the end.
3. once Ruby is installed next step is to set path
=>start => control panel => system =>advance => environment versiables
click path and press edit.
add
;C:\Ruby\bin
at the end of the path, I assumed that you have installed Ruby in drive c.
press oK.
4. now in command prompt, write
gem update --system
when the process completed, write
gem install rails
you have done. now its time to create your first project
in command prompt, write
rails firstproject
Once the projec is create, in command prompt, write
cd firstproject
ruby script/server
now browse
http://localhost:3000/
you will see ruby on rails welcome page.
by
faheem on August 18th, 2009
Public transport (also public transportation or public transit or mass transit) comprises passenger transportation service which is used by public [1].
An important role played by public transport in the society is to enable all the member of the society to travel, not only those having driving license and have access to their own automobiles.
Public transport like all other services and facilities in the third word countries is a real dilemma. Elite, which mostly uses their own private automobiles and vehicles, like all other public institutions, organization and facilities, rarely consider improvement in these services. As they never ever use it, so why care about it?
The fact however is, if government gave proper resources and made some improvements, public transit can play a very vital role in generating fair amount of revenue.
Traffic jam which is a real problem in the big cities can be decreased be providing well-designed transport system which is considered more dense then private transport.
I have been using public transport in my beloved country for the last two year, and can say that it has made me mentally sick.
People behave like animals. I am not blaming them for behaving like this, as they are put like animals in buses. They don’t care walking on your feet and pushing with their hands.
Young people specially students stand near entrance, making it hard for the people to get in and out.
Situation become even more deteriorating when a person with his bag selling books, handkerchiefs, toffees, and homeopathic medicines arrived in crowd and start speech explaining benefits of the product he owns.
Beggars also contribute to the noisy environment, trying hard to collect money for no work.