Welcome Guest, Not a member yet? Register   Sign In
Trying to use MVC
#4

[eluser]John_Betong[/eluser]
[quote author="d4v0" date="1226143716"]hey man!... do u have an e-mail... because... it doesn't work... i need an example where a controller get data from a model... and then show it in a view.

But this data is a query with more than one column... you got it??

I've been searching examples... but... i can't find what i want...! =([/quote]
 
Here you go I have just uploaded a new page to my website showing the last 42 jokes:
 
My Model Library
Code:
//=============================================
  function m_last_42() {
    $sql  = 'SELECT id, title FROM jokes ORDER BY id DESC LIMIT 0,22';
    $query = $this->db->query($sql);
        
    $data['thelot'] = array();
    if ($query->num_rows()) {
      foreach($query->result() as $row):
        $tmp = anchor_popup( 'joke/popup/' .$row->id,
                              $row->title,
                              $this->atts);
        $data['thelot'][]    .= $tmp;
      endforeach;
    }//endif
    return $data['thelot'];
  }//endfunc
 
 
My Controller
Code:
//=============================================
  function last_42() {  
    $data['joke_title'] = 'the Last 42';
    $data['last_42']    = $this->m_lib->m_last_42();
    $data['thelot'][]   = $this->load->view('_box_42', $data, TRUE);

    $this->j_view($data); // calls a common view with header, menus left & right and footer, etc  
  }//endfunc
 
 
My View
Code:
<html>
   ...
   ...
<body>

   <?php // this is the only bit you are concernced with  
                        // works for lists, Pictures only Searches
      if (is_array($thelot)) {
         foreach($thelot as $row):
            echo '<br />' .$row;
         endforeach;    
      }//endif
   ?&gt;

&lt;/body&gt;
&lt;/html&gt;
&nbsp;
&nbsp;
See it in action here: http://johns-jokes.com/joke/last_42
&nbsp;
&nbsp;


Messages In This Thread
Trying to use MVC - by El Forum - 11-07-2008, 09:47 PM
Trying to use MVC - by El Forum - 11-07-2008, 10:48 PM
Trying to use MVC - by El Forum - 11-07-2008, 11:28 PM
Trying to use MVC - by El Forum - 11-08-2008, 02:07 AM
Trying to use MVC - by El Forum - 11-08-2008, 06:49 PM
Trying to use MVC - by El Forum - 11-08-2008, 08:37 PM
Trying to use MVC - by El Forum - 12-10-2008, 08:19 AM
Trying to use MVC - by El Forum - 12-11-2008, 04:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB