![]() |
Sending variables from the controller to the view with Active Record Query (newbie question) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Sending variables from the controller to the view with Active Record Query (newbie question) (/showthread.php?tid=28752) |
Sending variables from the controller to the view with Active Record Query (newbie question) - El Forum - 03-20-2010 [eluser]Juan Velandia[/eluser] Im sending a query directly from the controller to the view to make a list within a list like this: placeholder 1 - section1 - section2 - section3 placeholder 2 - section4 - section5 - section6 the query in the controller: Code: $data['query1'] = $this->db->get('cms_placeholder'); Code: $data['query2'] = $this->db->where('idplaceholder',$idplaceholder); where the table cms_section has a column named idplaceholder, and here's the view: Code: <?php foreach ($query1->result() as $row): ?> But I always get this: Message: Undefined variable: placeholder. I don't want to pass variables via URL therefore I was thinking to put a query within the view to make the $placeholder available, but I'm sure there's a more elegant solution, Thanks in advance for any idea! Sending variables from the controller to the view with Active Record Query (newbie question) - El Forum - 03-20-2010 [eluser]Ben Edmunds[/eluser] The correct syntax is: Code: $data['query2'] = $this->db->get('cms_section') Or you can use method chaining if your using php5. Also, are you using $this->load->view('yourView', $data) in your controller? Sending variables from the controller to the view with Active Record Query (newbie question) - El Forum - 03-20-2010 [eluser]Juan Velandia[/eluser] @Ben. thanks a lot for your quick answer. I'll check it!. And yes I'm using $this->load->view(‘yourView’, $data) in my controller., Best Regards! |