Skip to content

Instantly share code, notes, and snippets.

@JasvinderSingh1
Last active September 25, 2020 13:09
Show Gist options
  • Save JasvinderSingh1/516136cd50a2ef6ac8a9538ef93cb1af to your computer and use it in GitHub Desktop.
Save JasvinderSingh1/516136cd50a2ef6ac8a9538ef93cb1af to your computer and use it in GitHub Desktop.
CodeIgniter Tips & Tricks
// .htaccess in codeigniter to remove index.php
Replace the below code in config.php file.
$config['index_page'] = "index.php"
// Remove index.php
$config['index_page'] = ""
create .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
In some cases the default setting for uri_protocol does not work properly. To solve this issue just open the file config.php located in application/config and then find and replace the code as:
// Find the below code
$config['uri_protocol'] = "AUTO"
// Replace it as
$config['uri_protocol'] = "REQUEST_URI"
If it is still not working
Just add the ? sign after index.php in the .htaccess file :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
// how to change default view folder in codeigniter
System -> Core -> Loader.php
Find below function and change the name.
public function __construct()
{
$this->_ci_ob_level = ob_get_level();
$this->_ci_library_paths = array(APPPATH, BASEPATH);
$this->_ci_helper_paths = array(APPPATH, BASEPATH);
$this->_ci_model_paths = array(APPPATH);
$this->_ci_view_paths = array(APPPATH.'views/' => TRUE);
log_message('debug', "Loader Class Initialized");
}
// sample of controller
<?php
ob_start();//we need to start session in order to access it through CI
Class Register extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->load->view('register_html');
}
}
// sample of model
<?php
Class User_model extends CI_Model {
public function load_rooms() {
}
}
// changing class active using php (css)
I used it in li of menu
<li <?php if($this->uri->segment(1)==""){echo 'class="active"';}?> ><a href="/">Home</a></li>
restful api in codeigniter
https://github.com/ajaysoftdeveloper/codeigniter-restserver
https://itsolutionstuff.com/post/codeigniter-3-restful-api-tutorialexample.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment