לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 02-11-2011, 05:40
  משתמש זכר tsachibenezra tsachibenezra אינו מחובר  
 
חבר מתאריך: 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
קוד PHP:
 customerOBG 


שבתוכו יש את האובייקט
קוד PHP:
 customerOBGdetails 


שאליו אני מעביר רק את ה ID של ה CUSTOMER ואת השפה

קוד PHP:
 public function chaceView()
    {
        
$this->customerDetail = new customerOBGdetails(array(    'customer_id' => $this->id
                                                                
'language_id' => $this->language_id));
    } 


עכשיו את זה אני מעביר ל VIEW

מה שקורה שכל הנתונים הבסיסים כבר קיימים
אבל אם אני ארצה לקבל נתונים מה
קוד PHP:
 customerOBGdetails 


אז תתבצע קריאה אחת כדי לשמור את הנתונים בתוך האובייקט
קוד 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 כמספר הלקוחות

תודה
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 13:41

הדף נוצר ב 0.11 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר