【问题标题】:Undefined property: CI_Loader::$input未定义的属性:CI_Loader::$input
【发布时间】:2014-07-24 20:00:24
【问题描述】:

我刚刚开始学习 CodeIgniter,但遇到了以下示例: 我的控制器:

类站点扩展 CI_Controller { 公共函数 __construct() {
父::__construct(); } 函数索引() { $this->load->view('options_view'); } 函数创建() { $数据 = 数组 ( 'title' => $this->load->input->post('title'), 'content' => $this->load->input->post('content') ); $this->site_model->add_record($data); $this->index(); } } 我的模型是: 类 Site_model 扩展 CI_Model { 函数 get_records() { $q = $this->db->get('articles'); 返回 $q->result(); } 函数 add_record($data) { $this->db->insert('articles',$data); 返回; } }

我的看法是:

<pre>
       <?php echo form_open('site/create');?>
    <p>
      <label for="title">Title:</label>
      <input type="text" name="title" id="title"/>
    </p>
     <p>
      <label for="content">Content:</label> 
      <input type="text" name="content" id="content"/> 
      </p>
      <p>
      <input type="submit" value="Submit"/> 
      </p>
      <?php echo form_close();?>
</pre>

所以当我点击提交按钮时,我收到如下错误: Severity: Notice Message: Undefined property: CI_Loader::$input Filename: controllers/site.php Line Number: 19

任何想法都会有用!谢谢!!

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    在你的控制器中试试这个。

     class Site extends CI_Controller 
          {
            public function __construct()
        {
    
             parent::__construct();
        }
        function index()
        {
        $this->load->view('options_view');
        }
            function create()
        {
        $data = array (
         'title' => $this->input->post('title'),
         'content' => $this->input->post('content')
        );
         $this->site_model->add_record($data);
         $this->index();
        }
          }
    

    不需要在函数create的输入语句前面使用load。 试试吧。。

    【讨论】:

    • 不提,如果你认为是答案,那么你可以接受答案。 :D
    【解决方案2】:

    线条应该是这样的

    'title' => $this->input->post('title'),
    'content' => $this->input->post('content')
    

    不是

    'title' => $this->load->input->post('title'),
    'content' => $this->load->input->post('content')
    

    你还需要在 parent::__construct(); 之后加载表单 helper.so添加这一行,或者你可以在你的 autoload.php 页面中添加

    $this->load->helper('form');
    

    如果您遇到任何问题,请告诉我。

    【讨论】:

    • 好的!谢谢,我正在使用 $autoload['helper']
    猜你喜欢
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 2020-08-13
    • 2021-11-25
    相关资源
    最近更新 更多