调用未定义的方法CI

调用未定义的方法CI

当我要提交帖子时,会出现此类错误。我尝试更改从数据库字段到视图的所有内容,但是每次运行代码时,我都会遇到相同的错误,但看不到问题出在哪里

职位控制器

<?php


class Posts extends CI_Controller{

    function __construct(){
        parent::__construct();
        $this->load->database();

    }

    public function index($page='home'){

        $data['posts']= $this->Posts_model->get_posts();

        $this->load->view('templates/header');
        $this->load->view('posts/index',$data);
        $this->load->view('templates/footer');
    }


    public function view($mjestoOdredista=NULL){


        $data['posts'] = $this->Posts_model->get_posts($mjestoOdredista);
        $post_id = $data['posts']['id'];
        $data['comments'] = $this->comment_model->get_comments($post_id);

        if(empty($data['posts'])){
            show_404();
        }
        $data['id'] = $data['posts'];

        $this->load->view('templates/header');
        $this->load->view('posts/view',$data);
        $this->load->view('templates/footer');
    }


    public function create(){
        //check if user is logged in
        if(!$this->session->userdata('logged_in')){
            redirect('users/login');
        }

       $this->form_validation->set_rules("mjestoPolaska", "Mjesto Polaska", 'required');
       $this->form_validation->set_rules("mjestoOdredista", "Mjesto Odredista", 'required');
       $this->form_validation->set_rules("datumPolaska", "Datum Polaska", 'required');
       $this->form_validation->set_rules("datumPovratka", "Datum Odredista", 'required');
       $this->form_validation->set_rules("cijena", "Cijena", "required");
       $this->form_validation->set_rules("brojMjesta", "Broj mjesta", 'required');
       $this->form_validation->set_rules("opis", "Opis", 'required');

        $data['title'] ='Create Posts';
        $data['categories'] = $this->Posts_model->get_categories();



        if($this->form_validation->run()){

            $this->load->view('templates/header');
            $this->load->view('posts/create',$data);
            $this->load->view('templates/footer');

        }else {

            //upload image
           $config['upload_path'] = './assets/images/posts';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '2048';
            $config['max_width'] = '500';
            $config['max_height'] = '500';

           $this->load->libary('upload', $config);

          if(!$this->upload->do_upload()){
                $error=array('error'=>$this->upload->display_errors());
                $post_image='noimage.jpg';
            }else{
                $data = array('upload_data'=>$this->upload->data());
                $post_image = $_FILES['userfile']['name'];
            }

            $this->Posts_model->create_post("Posts_model");
            $this->session->set_flashdata('post_creted', 'You post has been created') ;
            redirect('posts');
        }

    }

    public function delete($id){

        if(!$this->session->userdata('logged_in')){
            redirect('users/login');
        }


        $this->Posts_model->delete_post($id);
        $this->session->set_flashdata('post_deleted', 'You post has been deleted  ') ;
        redirect('posts');
    }



    public function edit($mjestoOdredista){
        if(!$this->session->userdata('logged_in')){
            redirect('users/login');

        }

        $data['mjestoOdredista']= $this->Posts_model->get_posts($mjestoOdredista);

        //Check if user is logged in
        if($this->session->userdata('user_id') !=$this->Posts_model->get_posts($mjestoOdredista)['user_id'])
            redirect('posts');
        $data['categories'] = $this->Posts_model->get_categories();

        if(empty($data['mjestoOdredista'])){
            show_404();
        }

        $data['id'] = 'Edit Post';
        $this->load->view('templates/header');
        $this->load->view('posts/edit',$data);
        $this->load->view('templates/footer');
    }


    public function update(){
        if(!$this->session->userdata('logged_in')){
            redirect('users/login');
        }

        $this->Posts_model->update_post();
        $this->session->set_flashdata('post_updated', 'You post has been updated ') ;
        redirect('posts');

    }

    }

?>


帖子模型

<?php


class Posts_Model extends CI_Model{

    public function __construct(){
        $this->load->database();

    }

    public function get_posts($mjestoOdredista=FALSE){
        if($mjestoOdredista === FALSE){

            $this->db->order_by('posts.id','DESC');
            $this->db->join('categories','categories.id = posts.category_id');
            $query=$this->db->get('posts');
            return $query->result_array();
        }

        $query=$this->db->get_where('posts', array('mjestoOdredista' => $mjestoOdredista));
        return $query->row_array();
    }

    //Kreiranje post
    public function create_post($post_image){
        $mjestoPolaska = url_title($this->input->post('title'));


        $data=array(
                'mjestoPolaska' => $this-> input -> post('mjestoPolaska'),
                'mjestoOdredista' => $this->input ->post('mjestoOdredista'),
                'datumPolaska' => $this->input ->post('datumPolaska'),
                'datumPovratka' => $this->input ->post('datumPovratka'),
                'brojMjesta' => $this->input ->post('brojMjesta'),
                'cijena' => $this->input ->post('cijena'),
                'opis' => $this->input ->post('Opis'),
                'category_id'=>$this->input->post('category_id'),
                'user_id' =>$this->session->userdata('user_id'),
                'post_image'=>$post_image

        );

        return $this->db->insert('posts',$data);
    }

    //Brisanje posta
    public function delete_post($id){
        $this->db->where('id',$id);
        $this->db->delete('posts');
        return true;
    }


    //editovanje posta
    public function update_post(){
        $mjestoPolaska=url_title($this->input->post('Mjesto Polaska'));
        $data=array(
                'mjestoPolaska' => $mjestoPolaska,
                'mjestoOdredista' => $this->input ->post('Mjesto Odredista'),
                'datumPolaska' => $this->input ->post('Datum Polaska'),
                'datumPovratka' => $this->input ->post('Datum Povratka'),
                'brojMjesta' => $this->input ->post('Broj Mjesta'),
                'cijena' => $this->input ->post('cijena'),
                'opis' => $this->input ->post('Opis'),
                'category_id'=>$this->input->post('category_id'),
                'user_id' =>$this->session->userdata('user_id'),
                'post_image'=>$post_image

        );
        $this->db->where('id',$this->input->post('id'));
        return $this->db->update('posts',$data);

    }

    public function get_categories(){
        $this->db->order_by('name');
        $query = $this->db->get('categories');
        return $query->result_array();
    }

    public function get_posts_by_category($category_id){

        $this->db->order_by('posts.id','DESC');

        $this->db->join('categories','categories.id = posts.category_id');
        $query=$this->db->get_where('posts',array('category_id'=>   $category_id));
        return $query->result_array();

    }

}



?>


错误在第74行,错误消息:
调用未定义的方法CI_Loader :: libary()

最佳答案

在构造函数中尝试

$this->load->library('upload');


更换线74

 $this->upload->initialize($config);
 $this->load->library('upload', $config);


请享用!我希望。会的。 :)

关于php - 调用未定义的方法CI_Loader::library(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44191142/

10-12 02:31