So, I have already asked for this problem today. But it has reiterate. So, the error is: A PHP Error was encountered Severity: Notice
Message: Undefined variable: news
Filename: views/main_text_view.php
Line Number: 5
A PHP Error was encountered Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/main_text_view.php
Line Number: 5
Controller:
<?php
if ( ! defined('BASEPATH')) exit ('No direct script access allowed');
class First extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('materials_model');
}
public function index()
{
$this->load->view('header_view');
$this->load->view('menu_view');
$this->load->view('about_me_view');
$this->load->view('navigation_view');
$this->load->view('search_view');
$this->load->view('main_text_view',$news);
$this->load->view('footer_view');
}
public function mat()
{
$data = array();
$data['news'] = $this->load->model('materials_model');
}
}
?>
Model:
<?php
if ( ! defined('BASEPATH')) exit ('No direct script access allowed');
class Materials_model extends CI_Model
{
public function get()
{
$query = $this->db->get('materials');
return $query->result_array();
}
}
?>
View:
<div id="main">
<div class="post"> <a name="TemplateInfo"></a>
<h1>Template Info</h1>
<?php foreach ($news as $one):?>
<p>Posted by <?=$one['author']?></p>
<?php endforeach; ?>
<p><strong>Enlighten 1.0</strong> is a free, W3C-compliant, CSS-based website template by <strong><a href="http://www.styleshout.com/">styleshout.com</a></strong>. This work is distributed under the <a rel="license" href="http://creativecommons.org/licenses/by/2.5/"> Creative Commons Attribution 2.5 License</a>, which means that you are free to use and modify it for any purpose. All I ask is that you include a link back to <a href="http://www.styleshout.com/">my website</a> in your credits.</p>
<p>For more free designs, you can visit <a href="http://www.styleshout.com/">my website</a> to see my other works.</p>
<p>Good luck and I hope you find my free templates useful!</p>
<p class="post-footer align-right"> <a href="http://web-mastery.info/" class="readmore">Read more</a> <a href="http://web-mastery.info/" class="comments">Comments (7)</a> <span class="date">Jan 09, 2007</span> </p>
</div>
<br />
</div>
</div>
</div>