Codeigniter configuration for Beginners
![]() |
Codeigniter Configuration |
In this lesson we are going to learn basic configuration in codeigniter.
this lesson are included database configuration,base_url configuration
1.Database Configuration:
Database Configuration is most important factor to insert,update,create and delete data using database. follow the below step and learn how to configure database in codeigniter.
=>Go to codeigniter/application/config and Find out and open database.php
$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );Note:
'hostname'=>'Your Host Name',
'username'=>'Your mysql username here',
'password'=>'Your Mysql password here',
'database'=>'Your database name',
i have configure my database.php file like below..
$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'test', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );2.Base_url Configuration:
create index.php file and write <?php echo base_url();?> in application/view page and run from your browser .you will get and error. because you have not setup autoload url yet.
First we need to autoload our url helper to work with base_url.
go to codeigniter/application/config and open autoload.php
and
find out the below lines:
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array();
Now Change The
$autoload['helper'] = array(); to $autoload['helper'] = array('url');
Now Run <?php echo base_url();?> from your application/view your result will be look like below: http://[::1]/codeigniter/ because you have not set your base_url yet.
=>How to set base_url:
go to your codeigniter/application/config and open config.php file now find out the below lines
$config['base_url'] = '';
now change $config['base_url'] = '';
to $config['base_url'] = 'http://localhost/codeigniter';
Note: Codeigniter is your Project name and localhost is your host name.
Now run <?php echo base_url();?> from your view your result will be look like below
http://localhost/codeigniter/
$autoload['helper'] = array(); to $autoload['helper'] = array('url');
Now Run <?php echo base_url();?> from your application/view your result will be look like below: http://[::1]/codeigniter/ because you have not set your base_url yet.
=>How to set base_url:
go to your codeigniter/application/config and open config.php file now find out the below lines
$config['base_url'] = '';
now change $config['base_url'] = '';
to $config['base_url'] = 'http://localhost/codeigniter';
Note: Codeigniter is your Project name and localhost is your host name.
Now run <?php echo base_url();?> from your view your result will be look like below
http://localhost/codeigniter/
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.