CodeIgniter 3.0.1 Tutorial 3 – Getting Rid of “index.php” from URL (with download)

In the previous tutorial, you learnt about the purpose of each and every folder in the /application/folder of your web applicaiton.

This is a short tutorial in which you will learn how to get rid of the “index.php” from the URL of your web application using a .htaccess file.


Problem

In a default installation of CodeIgniter 3, the URL looks like this

http://localhost/tutorial/index.php/1_hello_world/helloworld/requestModal

The URL looks bad because of the “index.php”. It is possible to get rid of “index.php” using a simple file in your application’s root.

Solution

The “index.php” can be removed by simply putting a .htaccess  file in the root of your web application. Download the file from GitHub

[button link=”https://github.com/codeonion/CodeIgniter-removing-index.php” type=”big” newwindow=”yes”] DOWNLOAD from Github[/button]

The .htaccess file should contain the following text. The link I have provided from my github repository is ready for you to use.

Now go to the root folder of your CodeIgniter web application and make sure that you put the .htaccess file there.

Now, you can safely change your URLs from

<form method=”post” action=”<?php echo base_url();?>index.php/1_hello_world/helloworld/”>

To

<form method=”post” action=”<?php echo base_url();?>1_hello_world/helloworld/”>

Note that it is still possible to keep using the “index.php” in your URLs and it will show up in URL if you do.

That’s it! You have successfully removed the “need” to have “index.php” in your URLs.


 

If you found my post helpful or have any questions, please leave a comment.

Back to CodeIgniter Tutorials

Codeigniter 2.20 – Sending E-mail using codeigniter

Back to CodeIgniter Tutorials

In CodeIgniter, sending e-mail is a simple process. First the library is loaded. Then the user provides e-mail related data. Finally, the E-mail is sent. Here is how E-mail is sent using a Controller in CodeIgniter

  1. Load the E-mail library of CodeIgniter
  2. Provide set of characters that are to be permitted in the E-mail address.
  3. Initialize the type of e-mail as html (options text or html)
  4. Provide Sender’s E-mail address
  5. Provide Receiver’s E-mail Address
  6. Provide BCC E-mail address
  7. Provide Subject of the E-mail
  8. Provide Body of the E-mail.
  9. Send the E-mail!

Following is the complete code of the above process.

Let me know in comments if there is something that you would like to know. And do like an share.

Back to CodeIgniter Tutorials

Codeigniter 2.20 – Learn how to make live search using Codeigniter

codeigniter live search

Back to CodeIgniter Tutorials

You may have seen live search <input> boxes all over the internet. Here is how to make that live search in reference to the design of the following image using Codeigniter 2.20 and 3.0.

codeigniter_json_encode1
Example of live search using input box

This technique will use the following steps.

  1. User types in an input box.
  2. A call is sent to controller with input parameters taken from input box.
  3. Controller calls model.
  4. Model searches database and returns with or without an input to the controller.
  5. Controller uses json_encode() on result of model and sends the data to view.
  6. View receives data from controller and shows it on the interface.

Please note that you must have a working codeigniter installation and database connection. You can use XAMPP for that if you need to test.

MODEL

Create a table of hotels and use the following model

VIEW

Then set up a view and add jquery and bootstrap support along with bootstrap-typeahead

 Controller

Finally, use the following code in a controller function to call the model from view.

With this done, you will now be able to use live search in your interface.

I hope you find this helpful. If you have any questions, then please post in the comments. I will be glad to help.

Kind Regards,

Codeonion

Back to CodeIgniter Tutorials