Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] learning how to pass data to a view
#1

[eluser]M4rc0[/eluser]
Hi all!

I believe code igniter user guide is not very clear of how to pass data to a view.

I am doing exactly what it says, although in the user guide example it's passing static data do the view and not dynamic, i think it should work anyway:

controller
Code:
function latest()
   {      //loading the model is in the constructor
         //set option menu as current
         $this->template->write('opt1', 'current');        
         //get latest added movies
         $data['header'] = 'Latest Movies';
       $data['query'] = $this->Movie_model->get_latest();
         // Write the browse view in the template        
         $this->template->write_view('content', 'movie/browse', $data, TRUE);
       // Render the template
       $this->template->render();
   }

model
Code:
function get_latest()
    {
        $query = $this->db->get('movies', 10);
        return $query->result();
    }

view
Code:
<h2>&lt;?=$header;?&gt;</h2>
<ul>
&lt;?php foreach($query as $movie):?&gt;

<li>&lt;?php echo $movie;?&gt;</li>

&lt;?php endforeach;?&gt;
</ul>
//Output: Object of class stdClass could not be converted to string
&lt;?php echo $query['name']; ?&gt;
//Output: Undefined index: name
//so maybe it's an object?
&lt;?php echo $query->name; ?&gt;
//Output: Trying to get property of non-object
//it has to be array then
&lt;?php echo $query; ?&gt;
//Output: Array
//yep, it's array..var_dump!
&lt;?php var_dump($query); ?&gt;
//Output:
array(1) { [0]=>  object(stdClass)#17 (17) { ["id"]=>  string(1) "1" ["name"]=>  string(5) "Teste" ["cover"]=>  string(32) "public/images/covers/nocover.jpg" ["cover_thumb"]=>  string(38) "public/images/covers/nocover_thumb.jpg" ["watched"]=>  string(1) "0" ["rate"]=>  string(1) "0" ["country"]=>  string(0) "" ["year"]=>  string(1) "0" ["comment"]=>  string(6) "blabla" ["imdb_link"]=>  string(0) "" ["trailer_code"]=>  string(0) "" ["director"]=>  string(0) "" ["actors"]=>  string(0) "" ["comp_link"]=>  string(0) "" } }

You see i'm trying many ways to show the data to find out how but none of them work :down:

Help! Something so simple it should be explained on user guide *frustraded*


Messages In This Thread
[SOLVED] learning how to pass data to a view - by El Forum - 09-24-2008, 02:26 AM
[SOLVED] learning how to pass data to a view - by El Forum - 09-24-2008, 02:31 AM
[SOLVED] learning how to pass data to a view - by El Forum - 09-24-2008, 02:39 AM
[SOLVED] learning how to pass data to a view - by El Forum - 09-24-2008, 02:44 AM
[SOLVED] learning how to pass data to a view - by El Forum - 09-24-2008, 11:00 AM
[SOLVED] learning how to pass data to a view - by El Forum - 09-24-2008, 11:13 AM
[SOLVED] learning how to pass data to a view - by El Forum - 09-24-2008, 11:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB