my model code
public function retrivecat()
{
$query = $this->db->get('category');
foreach ($query->result() as $row)
{
$data[] = $row->catname;
}
return $data;
}
My controller code
function addPost()
{
$username = $this->session->userdata('username');
$data = array(
'pageTitle' => 'ارسال مطلب',
'username' => $username
);
$this->load->model('category');
$data = $this->category->retrivecat();
$this->load->view('dashboard/post',$data);
}
my view code :
print_r($data);
exit();
but, this is not worked and display :
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: dashboard/post.php
Line Number: 72
For passing variables into the view you must do this:
function addPost()
{
$username = $this->session->userdata('username');
$data = array(
'pageTitle' => 'ارسال مطلب',
'username' => $username
);
$this->load->model('category');
$data['variable'] = $this->category->retrivecat();
$this->load->view('dashboard/post',$data);
}
Then in the view do print_r($variable);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.