Magic function library for Codeigniter like CakePHP
CodeIgniter is a powerful PHP framework with a very small footprint, and very useful for website.
Today I am going to introduce you the Magic function for CI like CakePHP.
What is Magic Functions
By using this library, you don’t need to do define any function in your models all functions which you want it has already created just like magic. There is a library
Magic.php which convert your function into Database Query and produce result as you want.
Magic.php in your local directory and place it into
application/library in your CI project. Now set this library in
application/config/autoload.php . so don’t need to load in every controller.
$autoload['library'] = array('Magic');
Now your magic library is ready to use with
$this->magic Instance of library.
->tableName set table name for fetch data from DB.
->findAll($conditions=array()) Get all data from table.
Now the magic begin.
$this->magic->tableName->findById(2); $this->magic->tableName->findByName('user'); $this->magic->tableName->findByUserName('user'); $this->magic->tableName->findByEmail('firstname.lastname@example.org');
Find All Results
$this->magic->tableName->findAll($conditions = array());
$this->magic->tableName->findCount($conditions = array());
Git repository : Download source code