Database Powered Template Parser Variable Pairs?

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){
   $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.

I may be reading your question wrong, but I think you may have confused yourself. The parser class is for not inputting information into a database. It's a simple templating system like smarty. Rather than echo php variables you use the pseudo curly braces in your view.

As far as wanting to more complicated scripts in your model rather than controller, is perhaps a little off. Your model should be for CRUD only. There really shouldn't be anything more than that. Creating your own library/helper would be serve repetitive coding.

Based on what I think you are trying to accomplish should be like:
1.) Retrieve news articles from DB in your model
2.) Iterate result object adding articles to an array in controller
3.) Create a view for outputting articles
4.) Iterate articles array in your view

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.