问题
My core class
class MY_Loader extends CI_Loader
{
public function template($template_name, $vars = array(), $return = FALSE)
{
if($return):
$content = $this->view('admin/common/header', $vars, $return);
$content = $this->view('admin/common/leftmenu', $vars, $return);
$content = $this->view('admin/common/topbar', $vars, $return);
$content .= $this->view($template_name, $vars, $return);
$content .= $this->view('admin/common/footer', $vars, $return);
return $content;
else:
$this->view('admin/common/header', $vars);
$this->view('admin/common/leftmenu', $vars);
$this->view('admin/common/topbar', $vars);
$this->view($template_name, $vars);
$this->view('admin/common/footer', $vars);
endif;
}
}
My function
public function index()
{
$title = "Hello Admin";
$this->load->template('admin/cmspages', $title);
}
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800">Blank Page </h1>
<?php echo $title ; ?>
</div>
i made common header footer and sidebar using ci_loader in core folder but unable to paas value in view page what i have to do?
i have tried these code please explain where i am wrong
回答1:
Your template
method (and CI view
method) awaits $vars
as array, but you are passing only string.
Correct usage would be:
public function index() {
$data = array(
'title' => 'Hello Admin',
);
$this->load->template('admin/cmspages', $data);
}
来源:https://stackoverflow.com/questions/58098399/how-to-pass-data-into-view-file