Results 1 to 7 of 7

Thread: [php] codeigniter

  1. #1
    Lieutenant Commander Mez's Avatar
    Join Date
    Sep 2003
    Location
    Milano
    Posts
    6.607

    Default [php] codeigniter

    Ho un problema per quanto riguarda il display di un singolo recordo da database.
    Se devo vederli tutti funziona, ma un singolo no...
    Per chi mastica questo framework

    controller:
    public function view()
    {
    $data['record'] = $this->broker_model->getBroker();

    $this->load->view('templates/single', $data);
    }


    modello:
    function viewBroker()
    {
    $query = $this->db->get('brokerage', array('id' => $id));
    return $query->result_array();
    }

    view:
    <?php echo $record->descrizione; ?>



    errore che mi da:
    Message: Trying to get property of non-object


    idee?

  2. #2
    Lieutenant
    Join Date
    Jan 2007
    Location
    Roma
    Posts
    4.723

    Default

    magari quando c'e' un unico record non ti torna un array ma un oggetto singolo?

    Last Exile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Unknowns
    Nuida FollettoInLutto Bard Tiarna . . . . . . . . . . . . . . . . Deo The Undaunted Rune Priest
    Amiag Blademaster Silver Hand. . . . . . . . . . . . . . Viol The Sacrificed Shadow Warrior
    Viola Vampiir Grove Protector. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    Nero Incubus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . DarkBane
    Naida Cabalist Phoenix Knight. . . . . . . . . . . . . . . . . . . . . . . . . . . . Viole No-Stealth Scout

  3. #3
    Lieutenant Commander Mez's Avatar
    Join Date
    Sep 2003
    Location
    Milano
    Posts
    6.607

    Default

    nono, se faccio echo r_print mi torna come array, stasera ti posto il log di r_print

  4. #4
    Master Chief Petty Officer Bers's Avatar
    Join Date
    Jul 2005
    Location
    Verona
    Posts
    2.085

    Default

    Quote Originally Posted by Mez View Post
    $data['record'] = $this->broker_model->getBroker();

    function viewBroker()
    {
    $query = $this->db->get('brokerage', array('id' => $id));
    return $query->result_array();
    }



    Non stai chiamando due funzioni diverse???
    [url=http://narutofantasyheart.forumcommunity.net/?t=9346526&st=0]

  5. #5
    Lieutenant Commander Mez's Avatar
    Join Date
    Sep 2003
    Location
    Milano
    Posts
    6.607

    Default

    Quote Originally Posted by Bers View Post
    Non stai chiamando due funzioni diverse???
    nono, nel controller ho la funzione view() che include il modello e la sua relativa funzione (quelle in rosso):
    $data['record'] = $this->broker_model->getBroker();

    senza il modello mvc, come fareste voi a prelevare informazioni dal db?

  6. #6
    Lieutenant Commander Mez's Avatar
    Join Date
    Sep 2003
    Location
    Milano
    Posts
    6.607

    Default

    Ho risolto cosi:

    modello
    function viewBroker($options = array())
    {
    if(isset($options['id'])
    $this->db->where('id', $options['id']);
    $query = $this->db->get('brokerage');
    if(isset($options['id'])
    return $query->row(0);
    return $query->result();
    }


    controller
    public function view($id)
    {
    $data['record'] = $this->broker_model->getBroker(array('id' => $id));

    $this->load->view('templates/single', $data);
    }



    ps: ma perchè non tiene l'indentazione il forum? -.-
    Last edited by Mez; 30th November 2011 at 16:28.

  7. #7
    Ensign Hardcore's Avatar
    Join Date
    Sep 2006
    Location
    Modena
    Posts
    3.550

    Default

    Devi are [indent]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
[Output: 61.86 Kb. compressed to 52.04 Kb. by saving 9.82 Kb. (15.87%)]