4 Advanced Tricks CI Developer can Use.

4 Advanced Tricks CI Developer can Use.

A CodeIgniter is a widely used Pre Processor Hypertext framework that aims to help developers write better-structured code and remove boilerplate tasks from the workflow.

In this article, I am going to explain some increases useful techniques to use when developing applications using Code-igniter.

1 Easier Configuration Parameters

TechTiq Solution the best services provider to clients hire ci developer in UK,  When growing libraries or something that requires configuration values for our purposes, we mainly need to use configuration parameters to ensure that it to be equipped to participate in its tasks. When doing so, we are able to use the snippet shown below to receive the configuration values.

$value  = $this->config->item( 'some_item' );

That is exceptional, what is Landing Page if we have now simply a few configuration parameters, however after we have to extract a dozen configuration parameters or so, loading values this annoying. Wouldn't it be great to load every parameter like the array we use within the configuration file? In an effort to do just that you simply must load it in the following way.

1 $this->load->config( 'config_file', true );
2 $options    = $this->config->item( 'config_file' );
3 // $options['some_item'];

And with that single line, our whole configuration file would be placed within the $choices array. And to further sweeten the deal, using this procedure also makes sure you avoid the title collision problem in configuration files. This way your parameters can be named anything you would like without worrying about different configuration files.

2. Allowing Optional Configuration Options

Build upon our earlier point, think a state of affairs where we'd wish to pass parameters to our library from both a configuration file or an options array when loading it. Might be we're utilizing the equal library in exceptional elements of our utility and the config options cannot be equal for every use case.

To be able to do that, location a personal _options member in your library and use a constructor like the following.

private $_options   = array();

public function __construct( $options = array() ) {
    if ( is_empty( $options ) ) {
        $this->load->config( 'config_file', true );
        $options    = $this->config->item( 'config_file' );
    $this->_options  = $options;

3 Leveraging HTML Emails

The ought to send HTML emails via your app is omnipresent, be it a newsletter or some automated welcome message. Why Hire Magneto Developer On Hourly Basis? Normally, you will do this through hand coding the corresponding HTML within the message parameter of our email object been there, accomplished that.

Well, it is no secret that the above process is beautiful unpleasant. The next tip isn't really a trick but basically a technique to take the expertise of some Hire CodeIgniter Developer performance the place it is sense.

Individually, I decide upon this process as I manage few of sites where I need to ship newsletters, and a number of different HTML emails, and utilizing templates will tremendously ease up the method.

To your utility's views folder, create a folder known as emails and location any HTML email you would wish to send within it, with the corresponding structure to be rendered via E-mails purchasers. And now, within the method the place you shoot off the emails, you can use the next code:

public function send_mail() {
    $this->load->library( 'email' );
    $this->email->from( 'jdoe@gmail.com', 'John Doe' );
    $this->email->to( 'jane_doe@gmail.com' );
    $this->email->subject( 'Some subject' );
    $this->email->message( $this->load->view( 'emails/message', $data, true ) );

A Few following of important things to keep in mind when using this technique

The email library must be installed to be able to send HTML emails

The information object used when loading the view should include the options used in the view

With this procedure, we are making use of the built-in performance of retrieving the content of a view file as a substitute of sending it to the output classification by using environment the third parameter to properly when loading the view.

4. Managing Application Versions

Let's face it nearly each recent PHP utility is a backend provider or an API. When you have used the Google Maps API, you have on the whole seen that Google allow us to move a variant parameter for us to tell it which version we are going to make use of.

Would not or not it's great if we will do this in our CodeIgniter applications? This way, we are able to create new models of our software while helping legacy version to ensure backward compatibility.

With this process, we will be able to use a single CodeIgniter set up to handle more than one versions of our software utilizing the equal index file. We will be able to select the version through passing a v parameter within the request.

There are a few things in order for this to work. First off, I am going to rename my utility folder. Considering the fact that this is the first version of my API, I will simplify it 1.0.0. After this, I am going to rename my index.PHP file, call it 1.0.0. PHP and change the application_folder line in it. Change line 75 with:

$application_folder = '1.0.0';

Now our application version is 1.0.0. Are we going to call that 1.0.0.PHP file instead of index? Without the doubt now not! Let's create a new index.Php file and add the following code to it.

define( 'API_VER', 'v' );

array_key_exists( API_VER, $_REQUEST ) ? $v = $_REQUEST[ API_VER ] : $v = '1.0.0';

if ( file_exists( "{$v}.php" ) ) {
    if ( is_dir( dirname( __FILE__ ) . "/{$v}" ) ) {
        require dirname( __FILE__ ) . "/{$v}.php";
    } else {
        $error  = new stdClass();
        $error->error        = true;
        $error->description  = 'INVALID_API_VERSION';
        echo json_encode( $error );
} else {
    $error  = new stdClass();
    $error->error        = true;
    $error->description  = 'INVALID_API_VERSION';
    echo json_encode( $error );

Right here, we are defining the parameter that we will use to pick the version. If no version is passed we use the 1.0.0 version. If a version is passed, we are certain there are a corresponding file and folder for that version. Or else, we throw an error.

To add more versions, we would like simply have to copy our 1.0.0 folder and the 1.0.0.php file, rename them according to the version we're going to create, change the application_folder variable in the file and start working on the next version of our API.

So as to add more versions, we might effectively copy our 1.0.0 folder and the 1.0.0.Php file, rename them in line with the version we are going to create, trade the application_folder variable in the file and begin working on the next version of our API. Once we suppose at ease sufficient with it, we will make it the variant through editing the index.PHP file.


I am hoping you have determined a few of these pointers useful as you may be noticed I have excited by Restful service since it's my opinion they are what as PHP Developer will have to be specializing in.


  1. Nice Blog, Keep sharing your ideas and information. Excellent ! I am truly impressed that there is so much about this subject that has been revealed and you did it so nicely Thanks Anika Digital Media seo services web design development graphic design


Post a Comment

Popular posts from this blog

Enterprise and Web Development are a Perfect Combination

Is WordPress Good For Website development ?

Why Website Design is Important for Business?