OK, I went through a database tutorial and eventually ended up with the following:
function index() {
$this->load->model('dataModel');
$data['rows'] = $this->dataModel->getAll();
$data = array('title' => 'NKADD Calendar of Events', 'main_content' => 'pages/contact');
$this->load->view('template/main', $data);
}
I am getting errors and I believe it has something to do with the $data array/variable getting confused, but I’m not sure how to fix it!
This is the view page, btw
foreach ($rows as $r) {
echo '<h1>' . $r->title . '</h1>';
}
An error is reached when viewing the page
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: rows
Filename: pages/contact.php
Any Assitance?
Well, you need not add to
$dataarray, array of variables, but to do something like this:Or adding elements to array, as:
This way you can access $title and $rows, and other vars in template.