pass two variables to main content
I need to pa开发者_开发百科ss two variables to a page and i'm not sure would i do it. I need to tell it to load a specific view and also pass sql results to this view.
// template.php
<?php
$this->load->view('includes/header');
$this->load->view($main_content);
$this->load->view('includes/footer');
?>
// my controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MyController extends CI_Controller {
function query()
{
$this->load->model('search');
$data['main_content'] = 'query_results';
$sql['rows'] = $this->search->getAll();
$this->load->view('includes/template', $data, $sql); // no clue how to pass $sql to the view
}
}
?>
Thanks a lot in advance for your help.
You should change your function to
function query()
{
$this->load->model('search');
$data['main_content'] = 'query_results';
$data['rows'] = $this->search->getAll();
$this->load->view('includes/template', $data);
}
Now you can access your results in the view via the variable $rows
.
You can find the reference here, section "Adding Dynamic Data".
精彩评论