Shaikh Sonny Aman’s Blog

previously www.mailtoaman.com

Orchid mvc framework tutorial : Basic example showing how to write a simple hello world application

Posted on | March 22, 2008 | No Comments

Originally from orchid blog at: http://orchid.phpxperts.net/2008/03/18/creating-a-basic-app-with-orchid/

Ok, lets try to create baby out of orchid :P

Take her at your place for date:

Copy the orchid folder to a location of choice where you like to host the app.

Make sure she is vergin

There should not be any app folder inside the orchid folder. If any, remove it.

Get inside of her, make her move…
Open up a console, go to the orchid directory. run:

$php cli.php skeleton test

You will find a new folder named app is created in orchid directory.

The last drop….

run the following command:

$php cli.php controller main

Bingo.. orchid is a very good mother and wont take 9 months to create a baby. You can see your baby at:
http://localhost/learn/test/orchidframework/index.php?main

Don’t forget to change the url as required for your setup.

Examining the baby:

in orchid/app/controllers folder a new file is created named main.php

and two more files in orchid/app/views/main/ folder naming base.php and hello.php.

What they do is really simple and easy to understand.

Here is the controller file content:

class main extends controller
{
function base()
{
$this->view->set(”name”,’main’);
}

function hello()
{
$this->view->set(”param1″,’World’);
}
}

and hello.php and base.php are normal php files.

http://localhost/learn/test/orchidframework/index.php?main

This line executes the base method of the controller named main. ‘Base’ method is called implicitly if no explicit method is asked for.

and http://localhost/learn/test/orchidframework/index.php?main/hello

calls the hello method of the controller main.

Simple, eh ?

Just one more thing, you can pass values to the view from controller. Look at the hello method once again.

$this->view->set(’param1′,’world’);

And here how the param1 is used in hello.php

Hello <?=$param1;?>

Orchid’s baby is really smart, right ?!!

Cheers :)

PHP Active record with relational foreign key support

Posted on | March 22, 2008 | 6 Comments

Many a time i wished  I could find a php active record or active model that will support relational table. Failure on this, I wrote my own and named it as ActiveRelationalRecord.

Say,  I have two tables  posts(idposts,title,body) and comments(idcomments,comment,date). Now, using Active relational record I can do the following:

$arr = new ActiveRelationalRecord();
//$arr->init(’posts’,$_POST);
$arr->init(’posts’,array(’idposts’=>’12′));
$arr->addRelation(’comments’);
//$arr->addRelation(’anotherrelationaltable’);

echo $arr->title ;
echo $arr->body;
$comms = $arr->comment;
foreach($comms as $com)
{

echo $com;
echo ‘<br/>’;

}

// $arcom = new ActiveRelationalRecord();
//$idcomms = $arr->idcomments;
//foreach($idcomms as $idcom)
//{

//$arcom->init(’comments’,array(’idcomments’=>$idcom));
//echo $arcom->date;
//echo ‘<br/>’;

//}

Or, say you have two tables, user(idusers,name,password) and userdetails(iduserdetails,email,telephone) .
So, ARR can help in the following way:

$arr = new ActiveRelationalRecord();
$arr->init(’users’,array(’idusers’=>’34′));
$arr->addRelation(’userdetails’);

echo $arr->name;
echo $arr->email;

Finally, I don’t like the idea that an ActiveRecord or Model should have functions like find which will return multiple
record. For such utility , there should be some resultset type class.

Lastly, in future I will update the relational query to associate with a class.

Any more idea plz ?

How to set Google analytics on joomla 1.5 to see number of visitors

Posted on | March 18, 2008 | 3 Comments

Google analytics is a powerful tool to know the site visit status. You can easily sign up with google analytics from www.google.com/analytics and register a domain. You will be provided with two codes, one for legacy which has limited features and another is new code with lots of features to enable various kind of graphs and stats for your site.

Copy the desired code and paste it on the footer.php in joomla. This file can be found on JOOMLA_DIR/includes/ directory.

It may take some time to reflect the status on google analytics due to built in cacheing feature of joomla. Wait for some time and you will get lots of information on google analytics when it is enabled.

:)

Joomla 1.5 SEO friendly url how to

Posted on | March 18, 2008 | 6 Comments

Creating SEO friendly url in Joomla 1.5 is very easy. You don’t need to download any modules now. Just follow the steps below:

1. Login to Administration panel.

2. Go to Site->Global Configuration from menu.

joomla_seo_menu.png

3. Change the SEO settings:

screenshot.png

4. Almost done. Now just rename the htaccess.txt to .htaccess.

Bingo.. you are done !!

Run windows XP, vista in Linux with InnotTek Virtual Machine

Posted on | March 14, 2008 | 2 Comments

Many of us abandoned  windows and  landed on linux. But many of us also works in web development. A great twist between the brow  appears when we need to test on Internet Explorer ( IE ).

So, how test web pages  in Linux on Internet Exploer  and IE7 ?

Solution is brought to you by InnoTek virtual Box !  Using virtual box you can install both windows xp and windows vista side by side. Not anly these two crap, also anything including another distro of Linux itself :D

VirtualBox can be found in the synaptic repository for Ubuntu 7.10. I have not checked it any earlier version. Or you can directly download it from: http://www.virtualbox.org 

Additional Links:

End documentation.

How to’s and tutorials

FAQ

Screenshots.

Happy Linuxing :)

index.php : Stepping into php Orchid framework

Posted on | March 13, 2008 | 6 Comments

Recently I had the opportunity to involve in php orchid framework developed by Hasin Hayder. This is a MVC framework with lots of feature a system would ever need. Many of these features are already implemented while some are still under development. And surely there will be some other feature which will be recommended by YOU.

I am going to write a series of articles stating my journey into Orchid. This will help me to store the knowledge that I learned and help as a documentation.

index.php:

All request is first come to index.php. It has only four line:

include(”core/ini.php”);
initializer::initialize();
$router = loader::load(”router”);
dispatcher::dispatch($router);

The ini file defines the __autoload function which dyanmically includes the necessary definition files for the required object. The search path includes

“/core/main”,
“/core/libraries”,
“/core/main/dbdrivers”,
“/core/main/cache”,
“/core/helpers”,
“/app/models”,
“/app/views”

initializer::initialize();

initializer is a class resides in “/core/main” directory having a static function initialze(). Any extra initializing will take place here. At present, Wednesday, March 12 2008, the function is blank.

$router = loader::load(”router”);

Here the $router object is loaded by the loader. Router is responsible to extract the controller and action information from the url.

dispatcher::dispatch($router);

Dispatcher, as the name implies,  finds the controller and calls the action. If there is no redirection request, it loads the view and shows the output.

Thats it so far.

Cheers.

svn failed to commit, file or resource is locked !

Posted on | March 13, 2008 | 8 Comments

Some times while committing a file or folder using svn it says the resource is locked ! It happens if we forcefully cancel  an ongoing update or commit, say by using Ctr+C.

To unlock the resource use:

$svn cleanup

This will unlock the content. Now do commit :)

Implementing a software Process: Example with case study

Posted on | March 11, 2008 | 5 Comments

Three practical process example. Please don’t take these personally, take it as a case study:

1. Once I was in a software company which used to be one of the renowned ones. They had about 50 tech stuffs and had a very good process.

But, unfortunately they used that single process for all of projects despite of their various size and nature and when their working people dropped to 6/ 7 they still sticked to this heavy process. The process seemed like a hammer to break a nut. People had to maintain lengthy time consuming process to communicate even in a very time constraint project.

Funny is that, I was put into work after days of ‘training’ on company rules and policy book and with a very
high level overview of my current project but at the first day with my team, I asked one of my mets, what to do? He explained me in a very low voice and plead me with a fright in the eyes not tell anyone that he briefed me !! Why ? It is beyond the company rule to transfer knowledge unless he is officially assigned (well documented assignment, approval etc).

Rather funny is that we had to prepare task mega list, task lists etc taking days together what we hardly needed in development. We used our own ‘non-standard’ task lists. The task list were mainly for the CEO who strongly believes there should be a process and he knew only a single process (I admit that process was quite perfect for large, offshore projects).

Besides, we had a theoretically short but practically lengthy or unreal way to prepare PCL(Project cost log).

About testing, there is a test team with test pcs and people. Now, the back end developers used accused for every front end look&feel issues cause the front end used to prepare by a senior stuff and perhaps the  qa+test manager  could not understand whats the difference between front end and backend. No testing was required or even asked ever for the back end components and modules as the qam had hardly any knowledge on technology, I appreciate his honesty, he admitted. Anyway, what I feel only smoke test using the UI is not enough and also I feel the qa+test managers should have atleast minimum development knowledge to understand the project.

2. In another company where is I was in was Enosis( calling out the name, as saying something good :P). The process slim and fit. It evolved with the stuffs feedback and what they feel to have. Nice interpersonal communication. For development, we had barely and paper process. We used to sit together with the tech lead( Why all the good tech lead are little bulky ;) ) who is very friendly. The project manager had always direct communication with the stuffs.

The developers are never had to think about the preparing any doc which is not related to directly their work. The managerial stuffs used to do those.

For pcl, the company believed on the developers, we had to just put how long we worked today on an MS excel sheet. The manager knew precisely who is working what and did his job.

The manager demander that he knew the least amount of development knowledge using the technologies used in the project. But, there were hardly any ‘lucky’ bad programing practice could scape unnoticed by him.

3. Presently I am Trippert labs. It is a very new (and small so far) office and developers here very independent. Teams are spread across the globe. So, we can work at home if we have a personal prob on office time. We can even play Table tennis at office time, have two double beds in ‘Green room’ if we need a nap or think quietly. Thing is that freedom prevails every where but the developers are sincere,smart and dedicated.

Even though process is required. And part of my job is to maintain a process. We usually maintain google doc with the foreign offices for our project status. But  developers hardly  uses that, naturally. I found it most difficult to impose a process.  I know ,  you may say, use an  Agile ! But still that is a harness. So, I keep my keen eyes on each developer for any problem they face to manage their task. We discovered that some tasks are unnoticed. Now I took the chance to take the first step. We now use one of the big white board to write our individual tasks, status,issue, what’s next for each team. Everybody is happy. Now, step by step we will adopt additional system to develop a process which fits the need.

( In the coming days, I would be asking you lots of question to build up the process for us.. wont you help me ?! :)  )

That is my point. We have to remember, a process is often a journey and not a destination. And imposing a process  on the people may often  hamper the product ( though I know there might be some hard nuts among the developers).

Select a random row from large mysql table in an optimized way.

Posted on | March 10, 2008 | 4 Comments

Random — This simple pronounced and apparently gentle looking word can make your brain randomly scattered.

We often need to select a random row from a table. … cutting short.. less time.

Prob: Need a random row from a table name ‘Dim’ which has 1,000,000 rows.

{selected only pad, i am in hurry :(}

1.

Create a stored procedure:

create procedure getDimRandom()
begin
declare cnt INT default 0;
DECLARE cur1 CURSOR FOR SELECT count(*) FROM dim;
open cur1;
fetch cur1 into cnt;

select pad from dim where pad=round(rand()*cnt);
end

Time: 1.32 sec max in 10 try

Prob: I like it

2. select floor(rand()*99999), pad from dim where pad = floor(0 + rand()*99999) limit 0,1;

Prob: here i used 99999 hard coded. can be passed from script page like php, perl.

Time: 4.32 sec max in 10 try

3. select pad, rand() as rnd from dim order by rnd limit 1

or select pad from dim order by rand() limit 1.

Time: 4.56 sec max in 10 try

horrible way:

bye for now.. check back later.

How to create polls with Polldaddy

Posted on | March 10, 2008 | No Comments

 So, you like have some polls showed up on your site? What should you do ? Design database, design the models and finally passing hours together with image processor to give a nice look.

There  is a easy solution offered by Polldaddy. Create an account instantly in polldaddy, create your poll. You can configure questions in various type including, single selection, multiple selection etc covering almost everything you will ever need.

Having configured the poll, polldaddy will give you a code, generally javascript. There is an option if you like a flash poll.

Paste the code where you need. Bingo !

Look at the following poll:

Javascript:



flash version:



By the way, you will have the polls with above options for FREE :).

« go backkeep looking »