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

Laravel Tutorial 1 : Installation in XAMPP

Lets get it straight. “You want to install Laravel”. With this tutorial, I am starting a Laravel series. My tutorials are short and to the point. So lets get started without any fuss.

Prerequisites

  1. Download Composer or visit their official website.
    • Select “Install Shell Menus” in setup as shown.

      composerInstallation  install shell menu
      install shell menu
    • Press Next and point the setup to  the php.exe. For example, in my case, it is
      D:\xampp\php\php.exe
  2. Download Git
  3. Download Laravel Installaion Files from Github

Now that you have downloaded and installed Composer and Git, you can now start the Laravel installation process.

Installation of Laravel

  1. Extract Laravel to the xampp/htdocs folder. These are the installation files.
  2. Right click on the extracted folder and select Use Composer here. (this is why you installed shell menu with composer)
  3. A command prompt will open with composer settings. Also note that you will be at your extracted Laravel install
  4. Type the following command and press Enter. Downloading of Laravel assets will start.

 

Laravel is now installed. Now we will create a project.

Create a Project

  1. Go to Run and type cmd. 
  2. Lets assume that the project we are making is called “codeonion“.
  3. Type the following command in cmd to make out project:
  4. Wait for installation to finish.

A project named “codeonion” is made from Laravel installation. Lets test it.

Testing of new project

  1. Open your browser.
  2. Go to the following link
    localhost/codeonion/public/
  3. If you see the following then the installation went ok
    laravelinstallation

That is it! Laravel has been installed. In the coming tutorials, I will explain configuration of Laravel and then a project will be made.

Codeigniter 2.20 – Autocomplete in Sublime Text

Back to CodeIgniter Tutorials

Sublime text is a powerfully simple text editor that makes coding part of the development easier than it once was. Autocomplete for PHP, HTML, CSS Javascript is handled easily by Sublime text. But as I am writing, there is no native support for Codeigniter.

Do you have to manually type the following lines all the time?

If you suddenly can’t remember the name of a library or you have just started learning Codeigniter and want to explore all commands, you might probably have to find an IDE with autocomplete facility.

Fortunately for us, there is an amazing package for sublime text that allows Autocomplete. In this post, I will show you how to set up Sublime Text to have autocomplete facility for Codeigniter.

  1. Download Sublime Text 2 Completions for CodeIgniter and Unzip.
  2. There will be a file named PHP-codeigniter.sublime-completions.
    You will have to copy this file to two locations (to be sure). One is the sublime packages folder and the other is as according to the Github page.
  3. First, open sublime text and go to Browse Packages as shown below:
    Sublime text browse packages
    Sublime text browse packages

    A folder with the following path will open:

    C:\Users\USERNAME\AppData\Roaming\Sublime Text 3\Packages

    or simply

    …\Sublime Text (n)\Packages

  4. Copy the (PHP-codeigniter.sublime-completions) file and paste the following folder which you can find using:

    ..\Sublime Text (n)\Packages\User

Next, open up Sublime Text and you will be able to use Autocomplete. for example, see the following image.

CodeIgnoter Autocomplete
CodeIgniter Autocomplete

That’s it! You now have autocomplete facility within Sublime Text. Please note that with changes to codeigniter in future, this post might become obsolete. If for some reason, it does not work, then let me know in comments.

I hope this guide helped you.

Please Share and Comment

Back to CodeIgniter Tutorials

Codeigniter 2.20 – Uploading files to a folder and Inserting in Database table

Back to CodeIgniter Tutorials

In this tutorial, I am going to show how to upload multiple files into a folder and insert its name in a database table. In an application, we may either have to upload a single or multiple files. Take freelancer.com portfolio page for instance. They allow freelancers to upload multiple files for the same portfolio item. So our goal here is the same. The goals are:

  1. Take one or multiple files as an input.
  2. Once submit is pressed, the file is uploaded.
  3. When the file is uploaded, an its name is inserted in the database table.

In order to understand this tutorial, you must know how to install, and use codeigniter. Follow the following links if you want to learn these steps.

Now lets begin!

In order to upload a file to a folder, first a view is built that takes File as an input and has a submit button. I am using a controller named c_upload and my view is v_uploader

VIEW: v_uploader

I am taking multiple files as an input.

If you wish to upload a single file, then all you need to do is to remove the “multiple” keyword in line 5. Here is the code.

 

CONTROLLER: c_upload

From view, I am calling a function called do_upload(). I also have another function set_upload_options().

Load these helpers

Load these libraries

Load this model

Finally, here are the functions

Note: In set_upload_options() function, you can configure upload path

Now the Model code

These are the steps explaining the program.

Back to CodeIgniter Tutorials

Hybirdigniter config file (hybridauthlib.php) guide

Hybrdigniter is an integration of HybridAuth and CodeIgniter. In this sub-tutorial, I am going to explain the usage of /applicaion/config/hybridauthlib.php which is found in the installation of HybridIgniter.

Get HybridIgniter-master

Complete Tutorial : Social media login setup in Codeigniter Site using Hybridigniter

The complete File

[expand]

 

[/expand]

Enable or Disable a social media service

This feature allows you to Enable or Disable social media services. For example, if I wish to disable twitter, then I will do the following:
FROM

To

Add Social Media Developer “key”/”id” and “secret”

The config file also allows you to add developer app specific key/id and secret code in the config file that allows integration for that specific app.

For example, look at the highlighted lines below:

Understand this to avoid “providers” variable error

While developing, you might happen to see an error saying that the $providers variable is not defined. Well, please understand that this is where the providers array is. This will expand to the Controller and then lead to the View.

I hope this helps. The tutorial in future will continue HERE

Please do share this blog post and do comment if you liked this guide.

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