1

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????

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.