codeigniter check for user session in every controller

Another option is to create a base controller. Place the function in the base controller and then inherit from this. To achieve this in CodeIgniter, create a file called MY_Controller.php in the libraries folder of your application. class MY_Controller extends Controller { public function __construct() { parent::__construct(); } public function is_logged_in() { $user = $this->session->userdata(‘user_data’); … Read more

how to get the base url in javascript

Base URL in JavaScript You can access the current url quite easily in JavaScript with window.location You have access to the segments of that URL via this locations object. For example: // This article: // https://stackoverflow.com/questions/21246818/how-to-get-the-base-url-in-javascript var base_url = window.location.origin; // “http://stackoverflow.com” var host = window.location.host; // stackoverflow.com var pathArray = window.location.pathname.split( “https://stackoverflow.com/” ); // … Read more

explain $CI =& get_instance();

It’s basically a Singleton Design Pattern that uses a function instead of a static method. To look deeper, check out the source code So basically, it doesn’t enforce the singleton, but it’s a shortcut to a public function… Edit: Actually, now I understand. For PHP4 compatibility they had to do a double-global-variable-hack to get it … Read more

Where do I put image files, css, js, etc. in Codeigniter?

I have a setup like this: application system assets js imgs css I then have a helper function that simply returns the full path to this depending on my setup, something similar to: application/helpers/utility_helper.php: function asset_url(){ return base_url().’assets/’; } I will usually keep common routines similar to this in the same file and autoload it … Read more

Enabling $_GET in codeigniter

Add the following library to your application libraries. It overrides the behaviour of the default Input library of clearing the $_GET array. It allows for a mixture of URI segments and query string. application/libraries/MY_Input.php class MY_Input extends CI_Input { function _sanitize_globals() { $this->allow_get_array = TRUE; parent::_sanitize_globals(); } } Its also necessary to modify some configuration … Read more