aslampatwary Posted August 17, 2013 Share Posted August 17, 2013 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'); }} Quote Link to comment https://forums.phpfreaks.com/topic/281268-what-is-the-meaning-of-this-code-ci-get_instance/ Share on other sites More sharing options...
hakimserwa Posted August 17, 2013 Share Posted August 17, 2013 (edited) 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 August 17, 2013 by hakimserwa Quote Link to comment https://forums.phpfreaks.com/topic/281268-what-is-the-meaning-of-this-code-ci-get_instance/#findComment-1445473 Share on other sites More sharing options...
trq Posted August 18, 2013 Share Posted August 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/281268-what-is-the-meaning-of-this-code-ci-get_instance/#findComment-1445573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.