codeigniter vol.2中的未定义变量

时间:2012-08-07 11:01:11

标签: database view model foreach controller

所以,我今天已经问过这个问题了。但它重申了这一点。所以,错误是: 遇到PHP错误 严重性:注意

消息:未定义的变量:新闻

文件名:views / main_text_view.php

行号:5

遇到PHP错误 严重性:警告

消息:为foreach()提供的参数无效

文件名:views / main_text_view.php

行号:5

控制器:

<?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');

    }


   }

?>

型号:

<?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();
    }
}

?>

查看:

<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>

0 个答案:

没有答案