0

I want to send two data arrays from my controller to view how can I do it ? Following is my controller code

class Home extends CI_Controller {
 public function box() {
    $url = $this->pageURL();
    $id_from_url = explode('/', $url);
    $id = $id_from_url[6];
    $query = $this->db->get_where('mc_boxes', array('idmc_boxes' => $id));
    $row = $query->row();
    $rowcount = $query->num_rows();
    if ($rowcount <= 0) {
        echo 'ID not found';
    } else {
        $box_id = $row->idmc_boxes;
        $customer_id = $row->customers_idcustomers;
        $language_id = $row->languages_idlanguages;
        $template_id = $this->getTemplateID($box_id);
        $template_data = $this->getTemplateData($template_id);
        $variables_data = $this->getVariables($customer_id, $language_id);
        $title = $variables_data[0]['value'];
        $this->load->view('template', $template_data);
    }
  }
}

In my template view when I echo $title it says it is undefined how can I send the whole $variables_data array with $template_data array

Thanks :)

1

2 Answers 2

2

Instead of using each array ,all do set to one

Like that,giving important sections only

...................
$data['template_data'] =  $this->getTemplateData($template_id);

$data['variables_data'] =  $this->getVariables($customer_id, $language_id);

$data['title'] =  $variables_data[0]['value'];

$this->load->view('template', $data);

you can take $template_data and $variables_data in view files

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

4 Comments

template_data is normal array and variables_data is a multi dimensional array how to get specific array items in view then ?
You can iterate through any level of array in view file . It will works the same fashion in normal php page
Thanks a lot for your help and quick response :)
don't forget to add, before doing anything: $data = array();
0

Generally you pass in data as:


$data['template_data'] =  $template_data;
$data['title'] =  $$title; 
....
$this->load->view('template', $data);

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.