Going Back To CodeIgniter

It’s has been months since I played around with CodeIgniter. I say, it’s time to head back into it. Or should I say, jump back head first. I just realized how much easier it is to whip out an application or two, by just piecing together a few lines of code.

The resulting code is light, fast and fairly efficient. I tried other PHP frameworks, like CakePHP, butĀ for some reason I can’t really explain, I just couldn’t latch on to it. It’s a weak try on my part, but I just feel much more comfortable with CodeIgniter. Maybe, it’s the simplicity.

In any case, both CakePHP and CodeIgniter requires some heat, starting a fire, and some baking. But, first off, I need to get reacquainted with CodeIgniter.

I’m back reading The User Guide.

Run Multiple Applications in CodeIgniter

You’ve installed CodeIgniter and you’ve written a couple of applications. Now, you want to run two of your applications under one install of CodeIgniter. The following article discusses how to run several applications within a single install of CodeIgniter. The approach is accomplished using Apache’s Virtual Host.

Install Apache Virtual Host

1. To add a virtual host, edit /etc/apache2/sites-available/default. We will use “vhostname” as the virtual hostname in this example. Edit the default file and add the following:

<Virtualhost *:80>
ServerName vhostname
DocumentRoot /var/www2
</VirtualHost>

2. Run the a2ensite script which enables your virtualhost within the apache2 configuration. It creates symlinks within /etc/apache2/sites-enabled.

# sudo a2ensite vhostname

3. Restart Apache

# sudo /etc/init.d/apache2 restart

4. Check your virtualhost if it’s working by pointing your browser to http://vhostname.

CodeIgniter Setup

One way of setting up CodeIgniter to support multiple applications, is to have separate folders for each application. You can set up your CodeIgniter directories like the following:

system/
 application/
  app1/
   config/
  app2/
   config/

1. Under the “app1/config” directory, edit the config.php file. Point your application to be hosted at vhostname by changing the following line:

$config['base_url'] = "http://vhostname/";

2. Copy the “index.php” file under the main CodeIgniter directory to the http://vhostname web root directory.

3. The “.htaccess” file recommended by CodeIgniter also needs to placed to the web root of http://vhostname.

4. Open your browser and check if your application is working by placing http://vhostname in the address bar of the browser.

5. Repeat steps 1-4 to add additional virtual hosts. That’s it.

If you have questions or suggestions, please leave a comment.

Code Igniter Is Great

I finally had a chance to evaluate Code Igniter for a couple of hours. The sample videos, tutorials, and online manual are simple and straightforward. I tried a couple of examples and they worked great. I can’t wait to get started with a couple of projects. I might try a simple todo list just to get my feet wet.

What impressed me most are the number of helpers and classes that are available for use. It’s quite comprehensive from email, form, array, file, date, smiley, just to name a few helpers. Why recreate the wheel if it’s already available.

It takes a little bit of used to the MVC framework because it’s completely a different paradigm. Separating code from design does make a lot of sense. I do see the potential for rapid development due to the simplicity of functions like queries to the database, for example.

One thing I want to figure out how to get a template system working.

After two hours with Code Igniter, I’m fairly impressed.

I can’t wait to dive deeper into Code Igniter.

Code Igniter vs CakePHP

In the next several weeks, I will be evaluating two PHP frameworks: Code Igniter and CakePHP. I have been coding in PHP for several years now, and that’s without the help of a framework. I would still recommend this approach to anyone who is learning PHP for the very first time.

Knowing the basics of a programming language is essential first and foremost. A programmer needs to know the ins and outs of a language before jumping on a framework.

One of the reasons I want to use a PHP framework is for the rapid development of applications. So, in the next two weeks I will be evaluating both frameworks. I’ll come back a few weeks later with my observations.