application/config/hooks.php.
file. Hooks are more often to be used in executing a script with a particular path within codeigniter. $this->load->model (‘Model_Name’);
<?php echo CI_VERSION;?>
system/core/CodeIgniter.php
directory and run the code given below :define('CI_VERSION', '3.0.0');
or
define('CI_VERSION', '3.0.1');
.
.
.
define('CI_VERSION', '3.1.0');
MySQL
ORACLE
SQLite
ODBC
FIREBIRD
CUBERID etc.
is_really_writable($file)
is_php($version)
html_escape($var)
config_item($key)
set_status_header($code[, $text = ”])
is_https()
remove_invisible_characters($str[, $url_encoded = TRUE])
is_cli()
get_mimes()
/css/styles.css /js/query.php
/img/blog/sample.jpg
set_exception_handler
set_error_handler
register_shutdown_function
which are useful in handling parse errors exceptions and fatal errors. class ModelName extends CI_Model {
function_construct()
{
parent::_construct();
}
}
$this->load->model('ModelName');​
If in case your model file is located in sub-directory of the model folder, then you have to mention the full path. For example, if your file location is application/controller/models/project/ModelName
. Then, your file will be loaded as shown below,$this->load->model('project/ModelName');
application/core/MY_Input.php
And then proceed to declare the class with Class MY_Input extends CI_Input { }
config.php
file and adding this code to it.date_default_timezone_set('your timezone');
// Refers to $config['base_url']
<img src="<?php echo site_url('images/myimage.jpg'); ?>" />
$this->load->library(‘session’);
$this->load->library('session');
$this->session
function add_post($post_data){
$this->db->insert('posts', $post_data);
$insert_id = $this->db->insert_id();
return $insert_id;
}
is_cli()
.C++
script could call a command and run code in models.is_cli()
method in the Codeigniter checks if the request is originated from the command line or not.TRUE
if the application is run through the command line and FALSE
if not.application/helpers
folder and if it is not available in that folder then it will check in the system/helpers
folder.$this->load->helper('file_name');
$this->load->helper('url');
application/config/autoload.php
file.$this->load->helper(
array('helper1', 'helper2', 'helper3')
);
application/config/config.php
file.$config['csrf_protection'] = TRUE;
localhost/codeigniter/
$route['default_controller'] = ' ';
use _remap()
method. The _remap method always get called even if URI is different. It overrides the URI.public function _remap($methodName)
{
if ($methodName === 'a_method')
{
$this->method();
}
else
{
$this->defaultMethod();
}
}
$this->load->helper(
array('helper1', 'helper2', 'helper3')
);
MY_Calendar extends CI_Calendar}
$db1 = $this->load->database('group_one', TRUE);
$db1 = $this->load->database('group_two', TRUE);
xss_clean()
method to filer data.$data = $this->security->xss_clean($data);
if ($this->security->xss_clean($file, TRUE) === FALSE)
{
//file failed in xss test
}​
application/config/config.php
file.$config['csrf_protection'] = TRUE;
$this->csrf_cookie_name = $this->csrf_token_name;
$this->_csrf_set_hash();​
function _csrf_set_hash()
{
if ($this->csrf_hash == '')
{
if ( isset($_COOKIE[$this->csrf_cookie_name] ) AND
$_COOKIE[$this->csrf_cookie_name] != '' )
{
$this->csrf_hash = $_COOKIE[$this->csrf_cookie_name];
} else {
$this->csrf_hash = md5(uniqid(rand(), TRUE));
}
}
return $this->csrf_hash;
}​
anchor($uri = '', $title = '', $attributes = '')
echo anchor('details/local/123', 'My Details', 'title="Details title"');
// Prints: <a href="http://example.com/index.php/details/local/123" title="Details title">My Details</a>
app/Config/Email.php
file. A basic example for demonstrating how you might send email is given below:$email = \Config\Services::email();
$email->setFrom('your@interviewbit.com', 'Your Name');
$email->setTo('someone@interviewbit.com');
$email->setCC('another@another-example.com');
$email->setBCC('them@their-example.com');
$email->setSubject('Email Test');
$email->setMessage('Testing the email class.');
$email->send();​
application/errors/errorgeneral.php
template.show_error(‘message’ [, int $statuscode= 500 ] )​
This function shows the 404 error message supplied to it by using the application/errors/error404.php
template.show_404(‘page’ [, ‘logerror’])​
log_message(‘level’, ‘message’)​