Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.