Codeigniter Basic

By means of a simple and well-designed toolkit, Code igniter is a commanding PHP framework. If we consider web applications with advanced features, then to create such an application Code igniter is one of the efficient PHP Frameworks. As it makes web application always ready, learning becomes easier. Also due to the usual PHP coding it makes the code portable and only because of this, Compared to other frameworks, Code Igniter is significantly simple and fast. Derived from the Model-View-Controller (MVC) development pattern, it is a software approach to unscramble application logic and presentation by alienating from PHP scripting. But in reality, web pages containing minimal scripting are allowable by codeigniter.

MVC structure of Code igniter:

Model: Basically data is represented by model and all its functions retrieve, insert and restructure the database information as model contains data logic and also represents classes, data structures etc.

Despite the fact of data validation, validation class validates the data by defining the validating object with a few assigned rules and certain error messages that have been programmed. In case of data sent by URL, automatic validation procedure has been provided by validation object.

View: is the information- in general a web page which is accessible to users. Just like a header or footer, we can say a page scrap in Code Igniter, which can either be RSS page or any page.

Controller: is just a name of a class file linked with a URI and it is loaded by Code Igniter. But, for loading purpose not only matching of controller’s name with first segment of Url is necessary, but also first character of class name is required in upper case. Here, the parent controller class is extended and all its functions are inherited by controller class. Function of controller, need to call is determined by second segment of the URL as it loads “index” function when clears.

Advantages:

1. Easy and hassle-free migration from server hosting to server hosting.
2. Easy to learn, adopt and deploy.
3. Easy handling and customizing.
4. A new functionality has been applied without affecting the customization at all.
5. Offers flexibility and easy management With MVC based framework.
6. Active Record Implementation is simply superb and easy to remember.
7. Provides easier configuration and customization of configuration files.
8. Facilitates easy working with a variety of developers.
9. Good collection of possessed libraries.
10. Awesome documentation of the user guide, which makes it easy for any coder to use the whole framework.
11. Enables to incorporate its own existing scripts as well as develop core libraries for the system, 12. Lightweight and extensive

Disadvantages :

1. Its PHP based only and not very object-oriented in some parts
2. PHP4 legacy code,
3. Company-driven instead of community-driven,
4. Irregular releases,
5. Framework itself has no built-in ORM (only via 3rd party solutions)

Benefits of Code Igniter:
1. A small track and astounding presentation.
2. Provision of broad compatibility along with standard hosting accounts,
3. Configuration and normal coding rules are not required.
4. Depiction of straightforward solutions.
5. Free from complex structures and development.

Example :

uday_model.php => model folder

<?php
class uday_model extends CI_Model{
function __construct()
{
parent::__construct();
$this->load->helper(‘url’);
}
function uday_model(){
parent::Model();
$this->load->helper(‘url’);
}

function getall(){
$this->load->database();
$query = $this->db->query(‘SELECT *FROM books ORDER BY(id) DESC’);
return $query->result();

}

}  ?>

uday.php => controller folder

<?php
class uday extends CI_Controller{
public function __construct()     {
parent::__construct();
$this->load->model(‘uday_model’);
}
function uday(){
parent::CI_Controller();
}
function main(){
$data[‘query’] = $this->books_model->getall();
$this->load->view(‘uday_main’,$data);
}
}     ?>

uday_main.php => view folder

<html>
<head>

</head>
<body>
<div id=”header”>

<table cellpadding=”5″ cellspacing=”5″ >
<tr>
<th>ID</th>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Year</th>
<th>Available</th>
<th>Summary</th>
</tr>
<?php
foreach($query as $row):{

}
?>
<tr>
<td><?=$row->id?></td><td><?=$row->title?></td><td><?=$row->author?></td>
<td><?=$row->publisher?></td><td><?=$row->year?></td><td><?=$row->available?></td>
<td><?=$row->summary?></td>
<?php echo “<td>”. anchor(‘books/input/’.$row->id,’Edit’) .”</td>”; ?>
<?php echo “<td>”. anchor(‘books/del/’.$row->id,’Delete’) .”</td>”; ?>

</tr>
<?php
endforeach;
?>
<?php echo $links; ?>
</table>

</body>
</html>

Posted in codeigniter

Leave a comment