the sun's not yellow it is chicken

Month: December 2011

$this->lang /* FAIL */

Note to self: when dealing with a multi-language site, in a CodeIgniter extended class constructor, do not attempt this:


protected $lang;
function __construct() {
parent::__construct();
$this->lang = $this->uri->segment(1);
}

Instead you will want to do this:


	protected $language;
	function __construct() {
		parent::__construct();
		$this->language = $this->uri->segment(1);
	}

See what I did there? ‘lang’ to ‘language’.

As it happens $this->lang, when in a CI constructor, will name-conflict with any native CI system library that needs to tap into something similar to $CI =& get_instance(), with a subsequent $CI->load->lang('some_library') call.

Thank me not.

© 2024 moonbug.org

Theme by Anders NorenUp ↑