Jump to content

Class Variables With Models?


ShoeLace1291

Recommended Posts

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
                           );
}

Link to comment
https://forums.phpfreaks.com/topic/212114-class-variables-with-models/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.