Welcome Guest, Not a member yet? Register   Sign In
how to access methods of controller from views
#3

[eluser]Amitabh Roy[/eluser]
Code:
$comment_display = $this->comment_display($row->id);


You are calling a method of your controller in your view. Its wrong.
If you need to get the blogs and its associated comments you need to define the logic and pull the data in the controller itself , then arrange it and then pass it to the view. What you are doing in the view needs to be done in the controller.


index Controller code
Code:
$blogEntries = array();

$counter = 0;
foreach($query->result() as $row){
    
    $comment   = $this->comment_display($row->id);
    $blogEntries["$counter"]['title']   = $row->title;
    $blogEntries["$counter"]['text ']   = $row->title;
    $blogEntries["$counter"]['comment'] = $comment;
    
    $counter++;
   }

$data[‘title’] = “Blog”;
$data[‘list’] = array(‘first’, ‘second’, ‘third’);
$data[‘blogEntries’] = $blogEntries;


Also have a look at the tutorials specified in http://codeigniter.com/wiki/Category:Help::Tutorials

These should help you in improving your codeigniter skills


Messages In This Thread
how to access methods of controller from views - by El Forum - 07-06-2011, 09:20 PM
how to access methods of controller from views - by El Forum - 07-07-2011, 01:51 AM
how to access methods of controller from views - by El Forum - 07-08-2011, 01:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB