02-11-2011, 05:40
|
|
|
חבר מתאריך: 06.06.07
הודעות: 749
|
|
טעינת כל הנתונים לפני העברה ל VIEW או רק מתי שצריך
מה המצב
האם זה תקין או לא???
אני מציג פה אובייקט שנקרא CUSTOMER
קוד PHP:
class customerOBGcollection extends itemOBGcollection
{
function __construct()
{
parent::__construct('customerOBG');
}
}
class customerOBG extends itemOBG
{
private $server_id = 0;
private $server_name = '';
private $server_path = '';
private $language_id = 0;
private $id = 0;
private $reg_date = 0;
private $last_update = 0;
private $link = 0;
private $active = 0;
private $publish = 0;
private $cat_level_1 = 0;
private $cat_level_2 = 0;
private $cat_level_3 = 0;
private $city_id = 0;
private $area_id = 0;
private $country_id = 0;
private $customerDetail = null;
private $customerSlider = null;
private $customerProperty = null;
function __construct($params = array())
{
parent::__construct();
$this->init($params);
}
public function __get($itemProperty = 'noneProperty')
{
if(isset($this->$itemProperty))
{
return $this->$itemProperty;
}
return 'none property';
}
public function init($params = array())
{
if(is_array($params) && !empty($params))
{
foreach ($params as $key => $value)
{
if(isset($this->$key))
{
$this->$key = $value;
}
}
}
}
public function chaceView()
{
$this->customerDetail = new customerOBGdetails(array( 'customer_id' => $this->id,
'language_id' => $this->language_id));
}
}
class customerOBGdetails extends itemOBG
{
private $id = 0;
private $customer_id = 0;
private $language_id = 0;
private $title = '';
private $short_text = '';
private $url_value = '';
private $long_text = '';
private $link_text = '';
private $image_1 = '';
private $image_2 = '';
private $image_3 = '';
private $image_4 = '';
private $meta_title = '';
private $meta_description = '';
private $meta_keywords = '';
private $exec = false;
function __construct($params = array())
{
parent::__construct();
$this->init($params);
}
public function __get($itemProperty = 'noneProperty')
{
if(!$this->exec)
{
$this->getData();
$this->exec = true;
}
if(isset($this->$itemProperty))
{
return $this->$itemProperty;
}
return 'none property';
}
public function init($params = array())
{
if(is_array($params) && !empty($params))
{
foreach ($params as $key => $value)
{
if(isset($this->$key))
{
$this->$key = $value;
}
}
}
}
private function getData()
{
$this->CI->db->from('customer_details');
$this->CI->db->where('customer_details.customer_id', $this->customer_id);
$this->CI->db->where('customer_details.language_id', $this->language_id);
$query = $this->CI->db->get();
if($query->num_rows() > 0)
{
$this->init($query->row_array());
}
$query->free_result();
}
}
מתי שאני טוען את המערכת אני מרים את האובייקט הזה עם הנתונים מה DB
שבתוכו יש את האובייקט
שאליו אני מעביר רק את ה ID של ה CUSTOMER ואת השפה
קוד PHP:
public function chaceView()
{
$this->customerDetail = new customerOBGdetails(array( 'customer_id' => $this->id,
'language_id' => $this->language_id));
}
עכשיו את זה אני מעביר ל VIEW
מה שקורה שכל הנתונים הבסיסים כבר קיימים
אבל אם אני ארצה לקבל נתונים מה
אז תתבצע קריאה אחת כדי לשמור את הנתונים בתוך האובייקט
קוד PHP:
private function getData()
{
$this->CI->db->from('customer_details');
$this->CI->db->where('customer_details.customer_id', $this->customer_id);
$this->CI->db->where('customer_details.language_id', $this->language_id);
$query = $this->CI->db->get();
if($query->num_rows() > 0)
{
$this->init($query->row_array());
}
$query->free_result();
}
מש שאומר שאם יש לי VIEW שאני מציג בו 10 לקוחות
בתוך הלולאה אני ניגש ל DB כמספר הלקוחות
תודה
|