hairynuggets
hairynuggets

Reputation: 3311

Codeigniter passing data from model to controller parser

I am about to implement the parser class to my codeigniter project and would like some guidance in passing the data from my model to the parser array. Which is the better more efficient way to do it.

My model gets the data and returns it to the controller. How can I get it into the array in the controller?

Model:

    function getSeo($data){

    $this->db->select('seo_title, seo_description, seo_keywords');
    $this->db->from('content');
    $this->db->where($data);

    $query = $this->db->get();

     $data = array();

foreach ($query->result() as $row) {
    $data[] = array(
         'seo_title' => $row->seo_title,
        'seo_description' => $row->seo_description,
          'seo_keywords' => $row->seo_keywords
    );
}

return $data;

}

Controller:

     $viewdata['pageseo'] = $this->Content_model->getSeo($data);

$viewdata = array(
    'seo_title' => 'My seo Title',
    'seo_description' => 'My seo description',
     'seo_keywords' => 'My seo keywords',
    );

What is the best way to get the data from my model into the '$viewdata' array, how is it done????

Upvotes: 1

Views: 6332

Answers (2)

Sakthi
Sakthi

Reputation: 363

There is function called result_array() which is used to get the result set as array and the below link may help you. This is the core library function.

Plz refer,

http://codeigniter.com/user_guide/database/results.html

Upvotes: 1

Sotiris K.
Sotiris K.

Reputation: 88

Since the getSeo function from your model returns an array, the Controller will store this information to your $viewdata array as well.

If you try a print_r($viewdata) you'll see that the structure is as expected. Which is $viewdata['seo_title'] => 'My seo Title'

and so on...

Upvotes: 1

Related Questions