Jump to content

What is the Meaning of this Code $CI =& get_instance();


aslampatwary

Recommended Posts

I am a learner of php. So i just joined with you. I need help to understand the php code.

 

I have seen a php file. where has a line of code was

$CI =& get_instance()

so Please explane me the line of code.  Full code of the file given bellow

 

-------------------------------------------------------------------------------------

if (!defined('BASEPATH')) exit('No direct script access allowed');require_once(FUEL_PATH.'models/base_module_model.php');class Courses_model extends Base_module_model {    public $record_class = 'Course';	public $required = array(		'title' => 'Please fill out the course name',		'slug' => 'Slug cannot be empty',	);    function __construct()    {		$CI =& get_instance();		$this->config->module_load(COURSE_FOLDER, COURSE_FOLDER);		$this->_tables = $CI->config->item('tables');        parent::__construct($this->_tables['courses']);        $this->load->module_model(COURSE_FOLDER, 'lessons_model');    }	 function list_items($limit = NULL, $offset = NULL, $col = 'title', $order = 'asc')	{		$data = parent::list_items($limit, $offset, $col, $order);		return $data;	}	function form_fields($values = array())	{		$fields = parent::form_fields($values);		unset($fields['created_at']);		return $fields;	}	function get_courses($where = array(), $order_by ='title', $limit = NULL, $offset = NULL, $return_method = NULL, $assoc_key = NULL)	{		$courses = $this->db->get($this->_tables['courses'])->result_array();		if($courses)		{			foreach($courses as &$course)			{				$course['lessons'] = $this->db->where(array('course_id' => $course['id']))->get($this->_tables['lessons'])->result_array();				if(is_array($course['lessons']))				{					foreach ($course['lessons'] as $key => &$lesson) {						$lesson['articles_count'] = $this->db->where(array('lesson_id' => $lesson['id']))->get($this->_tables['articles'])->num_rows();					}				}			}		}		return $courses;	}}class Course_model extends Base_module_record {	private $_tables;	function on_init()	{		$this->_tables = $this->_CI->config->item('tables');	}}
Link to comment
Share on other sites

What is it you want, that this code is not doing for you?

 

this part of the code that you are asking

$CI =& get_instance() is referencing an open instance of the object Courses_model.

remember the code you are asking of is an oop which is being extended from another code or class(Base_module_model) so for one to understand it clearely you also need to provide the Base_module_model class and that a big code to read.

 

the easy way would be you to explain where you are going wrong in the code so we can try to deburg the problem

Edited by hakimserwa
Link to comment
Share on other sites

 

 

I am a learner of php. So i just joined with you. I need help to understand the php code.

 

Please, CodeIgnitor is probably the worst designed/written of all the frameworks. its really not good code to be learning from unless of course you want to learn how to write poorly designed code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.