2017-09-16 31 views
0

投稿の編集と更新のためにCodeIgniter3フレームワークでコードを書いています。しかし、送信ボタンをクリックすると、404ページにリダイレクトされ、ここにそのようなページがないことが示されますenter image description hereコントローラで$データを作成しようとしましたが、動作しなかったモデルに移動しました。問題。ここに私の見解は以下のとおりです。ここで投稿を編集中にページが存在しないことをCODEIGNIT3フレームワークが示しています

<?php $attributes = array('class' => 'rex-forms', 'name' => 'editcourse', 'id' => 'editcourse', 'data-parsley-validate' => ''); ?> 
     <?php echo form_open_multipart('courses/update', $attributes); ?> 
     <input type="hidden" name="courses_slug" value="<?= $courses['courses_slug'];?>"> 

    <!-- General --> 

    HERE IS SOME CODE 

</form> 

は私のコントローラです:

public function edit($courses_slug) { 

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

     $data['courses'] = $this->popular_courses_model->get_popular_courses($courses_slug); 

     //check user 

     if($this->session->userdata('id') != $data['courses']['instructor_id']){ 
      redirect(''); 
     } 

     $data['categories'] = $this->courses_model->get_all_categories_for_courses(); 
     $data['title'] = 'Edit Course'; 

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

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

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

     $this->courses_model->update_post(); 

     $this->session->set_flashdata('post_updated', 'Your post has been updated'); 
     redirect('blog'); 
    } 

ここに私のモデルである:

public function update_post() { 
     //insert image 
      $config['upload_path'] = './assets/img/single_courses/'; 
      $config['allowed_types'] = 'jpg|png'; 
      $config['max_size']  = 4096; 
      $config['overwrite']  = FALSE; 
      $config['remove_spaces'] = TRUE; 

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


      if(!$this->upload->do_upload('userfile')){ 

       $post_image = ''; 
      } else { 
       $datar = array('upload_data' => $this->upload->data()); 
       $post_image = $_FILES['userfile']['name']; 
      } 

      //insert the user registration details into database 
      $slugtitle = mb_strtolower($this->input->post('name'), 'UTF-8'); 
      $slug = url_title($slugtitle); 

      $data = array(
       'title' => strip_tags($this->input->post('name')), 
       'duration' => $this->input->post('duration'), 
       'certification' => $this->input->post('certification'), 
       'price' => strip_tags($this->input->post('price')), 
       'begining' => $this->input->post('begining'), 
       'courses_description' => $this->input->post('description'), 
       'purpose' => $this->input->post('purpose'), 
       'courses_slug' => $slug, 
       'instructor_id' => $this->session->userdata('id'), 
       'category_id' => $this->input->post('category'), 
       'img' => $post_image 
      ); 

     $this->db->where('courses_slug', $this->input->post('courses_slug')); 
     return $this->db->update('courses', $data); 
    } 
+1

あなたはルーティングを使用しない場合、あなたはその後、funvtion更新 – Vickel

+0

@Vickel、おかげで未知のページを呼び出すコントローラ 'courses'を呼んでいます!私はルートを追加するのを忘れました:Dしかし、私は1つの質問があります。私はプログラミングでは新しいです。これらのルートは何ですか?ルートを追加する前になぜ機能しなかったのですか? –

+1

CIルーティングはhttps://www.codeigniter.com/user_guide/general/routing.htmlで非常によく文書化されています。ルーティングなしでは、ここのようなCI URLのアプローチに従います:https://www.codeigniter.com/user_guide/ general/urls.htmlは、あなたのスクリーンショットのように、あなたのコントローラ 'courses'の中から' update'関数を呼び出すことを意味します。 CIホームページのチュートリアルに従うと、たくさんのことを学べます! – Vickel

答えて

0

あなたはモデルpopular_courses_modelを使用しているが、あなたは自動ロードでモデルをロードしていますあなたのコントローラーにロードしていないためです。

$this->load->model('popular_courses_model'); 

ここにモデルから関数を投稿していない限り、モデルには特定の構成がありません。あなたがいないと仮定すると、あなたのモデルは、このような何かを見ている必要があります

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Popular_courses_model extends CI_Model 
{  
    public function __construct() 
    { 
     parent::__construct(); 
     // Whatever code you want in your constructor 
    } 

    public function update_post() 
    { 
     // your code here 
    }  
} 

をそして、あなたのモデルは、大文字と小文字とあなたの「モデル」フォルダ内のPopular_courses_model.phpだろう。助け

希望、

ポール

+0

私はこれらのモデルをhttps://yadi.sk/i/eISeHes13MwYsrに持っています。しかし、私は問題を解決する方法を知らない –

関連する問題