简体   繁体   English

加载视图错误codeigniter

[英]Load view error codeigniter

I'm new in codeigniter. 我是Codeigniter的新手。 I want to save something database. 我想保存一些数据库。 I have link localhost/index.php/blog/gerilim_controller/40 I want to save 40 to database. 我有链接localhost / index.php / blog / gerilim_controller / 40我想将40保存到数据库。

I wrote some code. 我写了一些代码。 This is my model code: Akim_model.php; 这是我的模型代码:Akim_model.php;

<?php
class Akim_model extends CI_Model
{
    function __construct()
    {
        parent::__construct();
            $this->load->database();
    }

    function ekle($data)
        {
          $ekle=$this->db->insert('gerilim',$data); 
          if($ekle){
         return 1;
        }else{
         return 0;
        }
        }
}
?>

This is my controllers code: Blog.php; 这是我的控制器代码:Blog.php;

 <?php
class Blog extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

        public function index()
        {
                $this->load->helper('url');     }

    public function gerilim_controller( $gerilim_id = NULL ) {
        echo $gerilim_id;
        $data=array('gerilim'=>$this->input->post('gerilim'));
            $this->load->model('akim_model');
            $sonuc=$this->akim_model->ekle($data);
            if($sonuc==1)
              echo "Successed"; 
           else
              echo "Failed";
    }


}
?>

But when $this->load->model('akim_model'); 但是当$this->load->model('akim_model'); its gives an error. 它给出了一个错误。 Where I am wrong? 我哪里错了?

THe file name must match the class name for your model: 文件名必须与您的模型的类名匹配:

<?php
  class Akim_model extends CI_Model {
    function __construct() {
      parent::__construct();
      $this->load->database();
    }

    function ekle($data) {
      $ekle=$this->db->insert('gerilim',$data); 
      if($ekle) {
        return 1;
      }
      else{
        return 0;
      }
    }
  }
?>

Also put your conditional statement in curly braces: 还要将条件语句放在花括号中:

    if($sonuc==1) {
      echo "Successed"; 
    }
    else {
      echo "Not successed";
    }

You should call your model using the class name: 您应该使用类名称来调用模型:

$this->akim_model->ekle($data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM