Archive for the ‘Uncategorized’ Category
CodeIgniter 1.7.2 released
The new CodeIgniter 1.7.2 release includes the following general changes:
- Compatibility for PHP 5.3.0
- The Form Helper class has been improved
- New simple Cart Class has been introduced (we commented something about it in an earlier post)
- A new function is_php() has been introduced
- Also, show_error() function allows to send HTTP responses.
This new release can be downloaded from here.
Get a single table field value from database using CodeIgniter
If you want to get a single value from a database table, then an easy way to achieve that in CodeIgniter could be:
$count = $this->db->query('SELECT count(*) as count FROM departments')->row()->count;
Replace department by your table name, and of course, replace count(*) as count by your desired field.
Using a super Controller class in CodeIgniter
CodeIgniter is easy to understand if you know how MVC design pattern works. Just need to define your model, your controller and your views.
However, sometimes you need to reuse code in all your site pages and probably you ask yourself “How do I do that?”.
Well, here is a simple tip that may help you to reuse generic data, fields, etc. in your CodeIgniter application.
The importance of a well-documented framework
At the time to choose for a framework, evaluating the documentation is a crucial step in that decision.
I remember the time I chose CodeIgniter as framework I researched many of the features compared with other frameworks like Kohana and CakePHP, before taking the final opinion.
Later, I found that the documentation as well as online community were one of the most important decisions when choosing for a framework.
CodeIgniter and AJAX using jQuery
jQuery has some interesting functions that allows you to add AJAX support easily.
If you are new on CodeIgniter, we’d recommend to check out the user guide. If you are new on jQuery, you can check the AJAX documentation.
The problem
You have a page that need to communicate with a controller function using an AJAX way. The CodeIgniter controller function returns an JSON or plain result.
For example, suppose we are building a time tracker tool based on a web clock. We want users (freelancers or employees) to clock in and clock out without leaving the page or refreshing the browser. So, an AJAX behavior will be nice when the user click on a Clock In and/or Out button.
The solution
Prepare a simple view and add a button or link:
<a href="#" class="round button clock" rel="next" id="timebutton">Clock In</a>
Prepare the controller to accept and respond results. To achieve that, I will create a new controller named Time and place the following function:
function ajax_clock()
{
// function code goes here
// and return results in json format
}
So, at our client side, we will execute AJAX calls to run this controller function.
What should we add to that function? Basically we want that each time the user clicks on the button, a new entry is logged into the database to tell the application that someone has been clocked in or out.
For that purpose, let’s create a time_model CodeIgniter model that encapsulates the communication between controller and database.
function clockit()
{
// clockit() model function goes here
// and return last state
}



