Kohana or CodeIgniter or CakePHP?

I am going to start on a small system for internal use and I wanted to re-think my choice of CodeIgniter because it does not have templates or ORM. Guess what, I landed with KohanaPHP. It sounds very tempting that a new MVC Framework based on CodeIgniter with new features (especially ORM) is here but the documentation is really really poor.

I tried googling for a book or tutorial and I was really disappointed to have found none. I tried Amazon.com for a book but no books. Looks like I have landed in some weird space that might be good looking but I need to get my hands dirty in the code to learn it and at the end of the day, it may seem that I have lost a lot of hours on this new Framework. Lets give it a try!

Update: As of today (28th July, 2010), I am working on YII, its good, powerful and blazing fast. It has all the feature of CakePHP too.

HashPakistan needs an admin panel

Well, my initial estimates were wrong. I thought I could retweet the posts and Twitter would give me accurate results. The problem is with twitter results. They are giving me wrong and irrelevant results.

Also, when I ask Twitter to only send me “positive” tweets, it sometimes does not mark most of the positive tweets as “positive”, in fact they are not marked at all. So there are the “positive” tweets, “negative” tweets, “questions” and “unknown” (or “unrated”) tweets. A quick look at these tweets and I can see many of them as good ones that should have been retweeted but they were not.

To get over this situation, I need to have an admin panel where I can see statistics and possibly “approve” the negative / unrated tweets.

Having previous experience working in Zend Framework, CakePHP and CodeIgniter, I would prefer to build it in Code Igniter. I will keep this page updated with more info.

CodeIgniter or CakePHP? can’t decide

Can’t decide between CodeIgniter or CakePHP for my personal project. CodeIgniter is faster in terms of performance but development is slow, CakePHP‘s cake-bake makes development faster but its performance is not good. My problem is that I need both. I want it at best performance since I will be handling millions even billions of domain records AND I cannot spend more time developing my own system.

Any ideas?

Creating and Installing crontabs using CodeIgniter

Last night, I was trying to get a crontab working in CodeIgniter, since my current project (a personal project) is using CodeIgniter now. I didn’t wanted to use the conventional approach of running crontabs and my code seperate.

Unfortunately, CodeIgniter does not have support for Crontabs and I didn’t wanted to user wget in linux crontab to initiate unwanted requests.

I spent some time and came up with a solution. It uses

  1. CodeIgniter backend
  2. Does not modify any core architecture of CodeIgniter
  3. Keeps configuration at one place

So enough of the summary and let me show you how its done.
Create a file (e.g. cron.php) in the same place as your index.php and system folder. Here is its code

/**
* @author 	    Asim Zeeshan
* @web         http://www.asim.pk/
* @date		13th May, 2009
* @copyright 	No Copyrights, but please link back in any way
*/

/*
|---------------------------------------------------------------
| CASTING argc AND argv INTO LOCAL VARIABLES
|---------------------------------------------------------------
|
*/
$argc = $_SERVER['argc'];
$argv = $_SERVER['argv'];

// INTERPRETTING INPUT
if ($argc > 1 && isset($argv[1])) {
$_SERVER['PATH_INFO'] 	= $argv[1];
$_SERVER['REQUEST_URI'] = $argv[1];
} else {
$_SERVER['PATH_INFO'] 	= '/crons/index';
$_SERVER['REQUEST_URI'] = '/crons/index';
}

/*
|---------------------------------------------------------------
| PHP SCRIPT EXECUTION TIME ('0' means Unlimited)
|---------------------------------------------------------------
|
*/
set_time_limit(0);

require_once('index.php');

/* End of file test.php */

Now, we need a controller e.g. test so the controller code could be something like this. Please note that normally we do not need to output anything from these controllers since they are doing some background work or sending emails but for the sake of giving an example, I will be output-ing something to elaborate the example.

/**
* @author 	    Asim Zeeshan
* @web         http://www.asim.pk/
* @date		13th May, 2009
* @copyright 	No Copyrights, but please link back in any way
*/</code>

class Test extends Controller {

function __construct()
{
parent::Controller();
}

function index()
{
echo "testing from index \n";
}

function test() {
echo "testing from test \n";
}
}

Now execute crontab on linux command prompt

php /full-path-to-cron-file/cron.php /test/index

Voila! all you need now, is to setup the crontab like you normally do.
This code is not shared under any license so feel free to copy/modify/use it. Please link back to this website / post in any way e.g. direct link, credits etc.

P.S. The examples above user PHP5 constructor, If you need to execute this code on PHP4, please modify the constructors.

Template Library for CodeIgniter, Simple, Fast and Easy!

If you have not noticed, I just got started on CodeIgniter. I was really disappointed today when I noticed the lack of a template system in CodeIngiter to skin my little application. They say

The Template Parser Class is not a full-blown template parsing solution. We’ve kept it very lean on purpose in order to maintain maximum performance.

Lucky for me, I got a little help here, the library is great and works well for the latest version of CI too best of all its small and does not modify the CI code in anyway. It just uses the already available code to skin the application. Sleak!

I made a couple of modifications in the original library, here are my modifications

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template {
	var $template_data = array();
		
	function set($name, $value) {
		$this->template_data[$name] = $value;
	}
	
	function load($template = '', $view = '' , $view_data = array(), $return = FALSE) {
		$this->CI =& get_instance();
		$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));			
		return $this->CI->load->view($template, $this->template_data, $return);
	}
	
	// load a default template 'template.php'
	function view($view = '' , $view_data = array(), $return = FALSE) {
		$this->CI =& get_instance();
		$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));			
		return $this->CI->load->view('template', $this->template_data, $return);
	}
}

/* End of file Template.php */
/* Location: ./system/application/libraries/Template.php */

So now I use it like

$this->template->view('my_view', $view_data);

instead of

$this->template->load('template', 'my_view', $view_data);

Hope it helps somebody.

Getting Started on CodeIgniter, the lightening fast PHP Framework

Today, I have started on CodeIgniter, one of the powerful PHP frameworks recommended by Rasmus Lerdorf

CodeIgniter is most often noted for its speed when compared to other PHP frameworks. In a critical take on PHP frameworks in general, PHP creator Rasmus Lerdorf spoke at frOSCon in August 2008, noting that he liked CodeIgniter “because it is faster, lighter and the least like a framework”.

Read more about it here.

So far what I can tell you is that it really is FAST. I have been coding in CakePHP and Zend Framework, but this framework is very fast. Truely speaking I did not felt any difference using it.

I will keep posting about my experience of CodeIgniter.