Saturday, 28 May 2016

Loading

Codeigniter Beginners

Code igniter Beginners  

     This tutorial explains how to install and configuration in  code igniter. 




Who is Code igniter ?
 CodeIgniter is right for you if:
ü  You want a framework with a small footprint.
ü  You need exceptional performance.
ü  You need broad compatibility with standard hosting accounts that run a variety of PHP versions and configurations.
ü  You want a framework that requires nearly zero configuration.
ü  You want a framework that does not require you to use the command line.
ü  You want a framework that does not require you to adhere to restrictive coding rules.
ü  You do not want to be forced to learn a templating language (although a template parser is optionally available if you desire one).
ü  You eschew complexity, favoring simple solutions.
ü  You need clear, thorough documentation.

Server Requirements 
ü  PHP version 5.1.6 or newer(latest).
ü  A Database is required for most web application programming. Current supported databases are MySQL (4.1+), MySQLi, MS SQL, Postgres, Oracle, SQLite, and ODBC.

Downloading Code igniter:
       Download Code igniter Source file in CodeIgniter V 2.2.0 (Current version).

Installation Instructions
 CodeIgniter is installed in four steps:
  1. Unzip the package.
  2. Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.
  3. Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key.
  4. If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings.
If you wish to increase security by hiding the location of your CodeIgniter files you can rename the system and application folders to something more private. If you do rename them, you must open your main index.php file and set the $system_folder and $application_folder variables at the top of the file with the new name you've chosen.
For the best security, both the system and any application folders should be placed above web root so that they are not directly accessible via a browser. By default, .htaccess files are included in each folder to help prevent direct access, but it is best to remove them from public access entirely in case the web server configuration changes or doesn't abide by the .htaccess.
After moving them, open your main index.php file and set the $system_folder and $application_folder variables, preferably with a full path, e.g. '/www/MyUser/system'.
One additional measure to take in production environments is to disable PHP error reporting and any other development-only functionality. In CodeIgniter, this can be done by setting the ENVIRONMENT constant, which is more fully described on the security page.




Alter blow Order :
  Config Class:

Anatomy of a Config File

By default, CodeIgniter has one primary config file, located at application/config/config.php. If you open the file using your text editor you'll see that config items are stored in an array called $config.
You can add your own config items to this file, or if you prefer to keep your configuration items separate (assuming you even need config items), simply create your own file and save it in config folder.
Note: If you do create your own config files use the same format as the primary one, storing your items in an array called $config. CodeIgniter will intelligently manage these files so there will be no conflict even though the array has the same name (assuming an array index is not named the same as another).

Loading a Config File

Note: CodeIgniter automatically loads the primary config file (application/config/config.php), so you will only need to load a config file if you have created your own.
There are two ways to load a config file:
  1. Manual Loading
To load one of your custom config files you will use the following function within the controller that needs it:
  $this->config->load('filename');
Where filename is the name of your config file, without the .php file extension.
If you need to load multiple config files normally they will be merged into one master config array. Name collisions can occur, however, if you have identically named array indexes in different config files. To avoid collisions you can set the second parameter to TRUE and each config file will be stored in an array index corresponding to the name of the config file. Example:
// Stored in an array with this prototype: $this->config['blog_settings'] = $config
$this->config->load('blog_settings', TRUE);
Please see the section entitled Fetching Config Items below to learn how to retrieve config items set this way.
The third parameter allows you to suppress errors in the event that a config file does not exist:
$this->config->load('blog_settings', FALSE, TRUE);
  1. Auto-loading
If you find that you need a particular config file globally, you can have it loaded automatically by the system. To do this, open the autoload.php file, located atapplication/config/autoload.php, and add your config file as indicated in the file.

Fetching Config Items

To retrieve an item from your config file, use the following function:
$this->config->item('item name');
Where item name is the $config array index you want to retrieve. For example, to fetch your language choice you'll do this:
$lang = $this->config->item('language');
The function returns FALSE (boolean) if the item you are trying to fetch does not exist.
If you are using the second parameter of the $this->config->load function in order to assign your config items to a specific index you can retrieve it by specifying the index name in the second parameter of the $this->config->item() function. Example:
// Loads a config file named blog_settings.php and assigns it to an index named "blog_settings"

$this->config->load('blog_settings', TRUE);



// Retrieve a config item named site_name contained within the blog_settings array

$site_name = $this->config->item('site_name', 'blog_settings');



// An alternate way to specify the same item:

$blog_config = $this->config->item('blog_settings');

$site_name = $blog_config['site_name'];

Setting a Config Item

If you would like to dynamically set a config item or change an existing one, you can do so using:
$this->config->set_item('item_name', 'item_value');
Where item_name is the $config array index you want to change, and item_value is its value.

Environments

You may load different configuration files depending on the current environment. The ENVIRONMENT constant is defined in index.php, and is described in detail in theHandling Environments section.
To create an environment-specific configuration file, create or copy a configuration file in application/config/{ENVIRONMENT}/{FILENAME}.php
For example, to create a production-only config.php, you would:
  1. Create the directory application/config/production/
  2. Copy your existing config.php into the above directory
  3. Edit application/config/production/config.php so it contains your production settings
When you set the ENVIRONMENT constant to 'production', the settings for your new production-only config.php will be loaded.
You can place the following configuration files in environment-specific folders:
·         Default CodeIgniter configuration files
·         Your own custom configuration files
Note: CodeIgniter always tries to load the configuration files for the current environment first. If the file does not exist, the global config file (i.e., the one inapplication/config/) is loaded. This means you are not obligated to place all of your configuration files in an environment folder − only the files that change per environment.

Helper Functions

The config class has the following helper functions:
$this->config->site_url();
This function retrieves the URL to your site, along with the "index" value you've specified in the config file.
$this->config->base_url();
This function retrieves the URL to your site, plus an optional path such as to a stylesheet or image.
The two functions above are normally accessed via the corresponding functions in the URL Helper.
$this->config->system_url();
This function retrieves the URL to your system folder.
URL :




Autoload Class
The following items can be loaded automatically:
·         Core classes found in the "libraries" folder
·         Helper files found in the "helpers" folder
·         Custom config files found in the "config" folder
·         Language files found in the "system/language" folder
·         Models found in the "models" folder
To autoload resources, open the application/config/autoload.php file and add the item you want loaded to the autoload array. You'll find instructions in that file corresponding to each type of item.
URL :
https://github.com/bcit-ci/CodeIgniter/blob/develop/application/config/autoload.php

https://github.com/bcit-ci/CodeIgniter/blob/develop/application/config/routes.php






No comments:

Post a Comment