Author Topic: Class Variables With Models?  (Read 626 times)

0 Members and 1 Guest are viewing this topic.

Offline Hybrid Kill3rTopic starter

  • Enthusiast
  • Posts: 344
    • View Profile
    • LenseReflex.com
Class Variables With Models?
« on: August 30, 2010, 06:23:38 PM »
I want to pass a class variable from a model to a controller.  Basically something like this:

Code: [Select]
$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
                           );
}

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: Class Variables With Models?
« Reply #1 on: August 30, 2010, 06:45:56 PM »
Your description of your problem leaves allot to be desired.

Offline petroz

  • Enthusiast
  • Posts: 178
    • View Profile
Re: Class Variables With Models?
« Reply #2 on: August 31, 2010, 01:00:35 PM »
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.

Offline Hybrid Kill3rTopic starter

  • Enthusiast
  • Posts: 344
    • View Profile
    • LenseReflex.com
CodeIgniter Database Variable Pairs
« Reply #3 on: August 31, 2010, 09:06:02 PM »
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.
Code: [Select]
$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.

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: Class Variables With Models?
« Reply #4 on: August 31, 2010, 09:26:47 PM »
Your description really is still pretty vague.

Offline petroz

  • Enthusiast
  • Posts: 178
    • View Profile
Re: Class Variables With Models?
« Reply #5 on: August 31, 2010, 09:28:11 PM »
Post your model controller and view.