ShoeLace1291 Posted August 30, 2010 Share Posted August 30, 2010 I want to pass a class variable from a model to a controller. Basically something like this: $query = $this->db->query("SELECT * FROM news ORDER BY id DESC LIMIT 10"); foreach($query->result() as $news){ $this->news->getInfo($news->id); $data = array( 'ID' => $id, 'TITLE' => $title, //All of these variables would be set by the news->getInfo function 'BODY' => $body, 'DATE' => $date ); } Quote Link to comment https://forums.phpfreaks.com/topic/212114-class-variables-with-models/ Share on other sites More sharing options...
trq Posted August 30, 2010 Share Posted August 30, 2010 Your description of your problem leaves allot to be desired. Quote Link to comment https://forums.phpfreaks.com/topic/212114-class-variables-with-models/#findComment-1105383 Share on other sites More sharing options...
petroz Posted August 31, 2010 Share Posted August 31, 2010 make sure you are setting a variable on the controller like so. $data = $this->model->method($id); and on your model, use the return function to pass the data back. Like so.. return $data; If you can post more core, we can prob help you better. Quote Link to comment https://forums.phpfreaks.com/topic/212114-class-variables-with-models/#findComment-1105684 Share on other sites More sharing options...
ShoeLace1291 Posted September 1, 2010 Author Share Posted September 1, 2010 I have a list of news articles that I want to be able to parse with database queries. I read the guide on the template parser class and the variable pairs example that they used is pretty much what I want to do. The only thing is that I really can't figure out how to make it database powered. $query = $this->db->query("SELECT * FROM news ORDER BY id DESC LIMIT 10"); foreach($query->result() as $news){ $this->news->article($news->id); $data = array( 'ID' => $news->id, 'TITLE' => $this->news->title, 'BODY' => $this->news->body ); } $this->parser->parse('index_body.tpl', $data); The reason I want to do this is because it makes templating easier and it also makes it easier to execute more complicated scripts in the model without having to do it in the controller. Quote Link to comment https://forums.phpfreaks.com/topic/212114-class-variables-with-models/#findComment-1105899 Share on other sites More sharing options...
trq Posted September 1, 2010 Share Posted September 1, 2010 Your description really is still pretty vague. Quote Link to comment https://forums.phpfreaks.com/topic/212114-class-variables-with-models/#findComment-1105912 Share on other sites More sharing options...
petroz Posted September 1, 2010 Share Posted September 1, 2010 Post your model controller and view. Quote Link to comment https://forums.phpfreaks.com/topic/212114-class-variables-with-models/#findComment-1105913 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.