Build a Blog with CodeIgniter: Part 1
Date Posted: 03/24/2010 - 01:54 am
In this series of posts, I will show you how to build a blog like this one using Codeigniter (CI) and jQuery. In the first post, I will explain how to install and configure codeigniter so we can begin building your blog.
Next navigate to the system->application->config folder. Here you will find all of the, as you guessed it, configuration files for your ci setup. Open the config.php file. In this file you can edit things like enabling the global XSS filter, setting time settings, or, if you plan on using sessions, set your encryption key. For now we are going to make the following changes:
1) Set your base URL
For example if you wrote:
Now to test if everything worked, go to the address where you uploaded CI and if you see "Welcome to CodeIgniter!" it worked!
Cheers and please feel free to leave any questions or comments.
Download
Step one is to simply download the most recent copy of codeigniter here (Version 1.7.2 at the time of this writing). Unzip and extract the file and we can move on to step 2.Configure settings
Navigate to the recently extracted codeigniter folder and open the index.php file. In this file you can set PHP's error reporting level or change the system or application folder name. If you do choose to change either the system or application name, make sure you rename the appropriate folder to the name you specified.Next navigate to the system->application->config folder. Here you will find all of the, as you guessed it, configuration files for your ci setup. Open the config.php file. In this file you can edit things like enabling the global XSS filter, setting time settings, or, if you plan on using sessions, set your encryption key. For now we are going to make the following changes:
1) Set your base URL
$config['base_url'] = "http://yoursitehere.com/";or if you want to place your blog somewhere other than the 'home'/index page
$config['base_url'] = "http://yoursitehere.com/blog";2) Set your encryption key found near the end of the file (more info on this ci user guide )
$config['encryption_key'] = ""; //this is to be a 32 character random string3) Set you cookie info for sessions. You can choose to encrypt your cookie or not, but, at least for the scope of this article, the only person that is going to be logging in or out is you, since we are only going to be using sessions/cookies for authenticating users who can add articles to the blog.
$config['sess_cookie_name'] = 'your_session_cookie_name'; $config['sess_expiration'] = 7200; $config['sess_encrypt_cookie'] = FALSE; $config['sess_use_database'] = FALSE; $config['sess_table_name'] = 'your_session_cookie_table'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = TRUE; $config['sess_time_to_update'] = 300;
Configure database
Now open the system->application->config->database.php. This is a configuration file specifically for your database. Here you will specify your db username, password, hostname, and db driver. We will get into caching later in the tutorial.$active_group = "default"; $active_record = TRUE; // In this tutorial we will be using active record. $db['default']['hostname'] = "localhost"; $db['default']['username'] = "YOUR USERNAME"; $db['default']['password'] = "PASSWORD"; $db['default']['database'] = "DATABASE NAME"; $db['default']['dbdriver'] = "mysql"; // could also be postgres, odbc, mssql, mysqli $db['default']['dbprefix'] = ""; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci";
Configure routes
Now open up the system->application->config->routes.php file. This file contains the 'first' controller to be loaded. In the next section of this tutorial we will change this, but for now keep it as it is.$route['default_controller'] = "welcome"; $route['scaffolding_trigger'] = "";
Installing codeigniter
Now ftp or copy your system folder and index.php to where you specified in the system->application->config->config.php.For example if you wrote:
$config['base_url'] = "http://yoursitehere.com/";You would now copy the files to the root (httpdocs) of your server, or if you wrote
$config['base_url'] = "http://yoursitehere.com/blog";you would copy the files to the blog folder.
Now to test if everything worked, go to the address where you uploaded CI and if you see "Welcome to CodeIgniter!" it worked!
In part 2
I will quickly explain how CI's MVC works, write a start page that displays your articles, and also a simple admin area where you can add/edit/delete your posts.Cheers and please feel free to leave any questions or comments.




rss feed
1
comments