Save 100s of Dev Hours - Get The React Codebase Generator

Codeigniter best tricks and hacks

Codeigniter best tricks and hacks

Hi Friends,
Today I am sharing you some best tricks i have used in couple of projects, may be these things are common but we need these in all of our projects and we can find it on google but by different different authors, i am providing all the codeigniter tips tricks and hacks in this single article. if i missed any other trick then please let me know through comments, I will update it to my article.

Now please find the

Codeigniter best tricks and hacks

1: Remove index.php from url codeigniter

Solution : we need to update the .htaccess with following code:

2: Call Controller function or varriable from view

Solution : We need to pass the controller self object to its view to call the function or varriable of that controller . please follow instructions:

3: Db prefix in core queries

Solution : in database.php we need to pass swap_pre in configuration index in db config array. please see example:
In database.php there is a config array start with following:

So in this list there is a index named db_prefix
this is general usage in CI auto qyuiry builder class
but if we are writing the core queries then we need to pass any string like:

now we can use the swap_pre value appending before table name in our query as following:

4: Call model and its function from library and helpers

Solution : we can load any model from helper or library by instantiating the ci global object using call by refrence as following:

5: Get rendered html of your view in a Controller’s varriable

Solution : Use third parameter as true in this load view


You May Also Like

About the Author: Jeetendra Singh

Jeetendra Singh is a UI Architect who has 10+ Years of Experience as Full Stack Developer. He is a Microsoft certified technology Specialist and AWS Certified Associate Architect. His Major Interests are in Mongo Db, Express Js, React Js, Node Js (MERN STACK). He build variety of applications using Mern, Mean, Node, JavaScript & jQuery