2014-10-31 2 views
0

저는 방금 codeigniter로 작업하기 시작했습니다. 이제는 소규모 프로젝트의 관리 제어를 담당하고 있습니다. 클라이언트 정보 목록이 있습니다. 내가보기 & 편집 버튼을 클릭하면 Client List404 페이지를 찾을 수 없음 codeigniter에 오류가 있습니까?

의 페이지를 편집 할 수 리디렉션 나에게 내가 응용 프로그램/설정/routes.php

$route['admin/clients'] = 'admin_clients/index'; 
    $route['admin/clients/add'] = 'admin_clients/add'; 
    $route['admin/clients/update'] = 'admin_clients/update'; 
    $route['admin/clients/update/(:any)'] = 'admin_clients/update/$1'; 
    $route['admin/clients/delete/(:any)'] = 'admin_clients/delete/$1'; 
    $route['admin/clients/(:any)'] = 'admin_clients/index/$1'; //$1 = page number 

코드 경로를 구성한 error page

404 오류를주는

<td class="crud-actions"> 
        <a href="'.site_url("admin").'/clients/update/'.$row['id'].'" class="btn btn-info">view & edit</a> 
        <a href="'.site_url("admin").'/clients/delete/'.$row['id'].'" class="btn btn-danger">delete</a> 
       </td> 

짝수 삭제로 인해 giv가 작동하지 않습니다. 나에게 같은 오류를 일으켰다. 여기

RewriteEngine on 
RewriteBase /testing_palace/ 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

날 여기이 문제를 해결하기 위해 도와주세요 내 컨트롤러 파일

<?php 

class Admin_clients extends CI_Controller { 

    /** 
    * name of the folder responsible for the views 
    * which are manipulated by this controller 
    * @constant string 
    */ 
    const VIEW_FOLDER = 'admin/clients'; 

    /** 
    * Responsable for auto load the model 
    * @return void 
    */ 
    public function __construct() { 
     parent::__construct(); 
     $this->load->model('admin_client_model'); 
     if (!$this->session->userdata('is_logged_in')) { 
      redirect('admin/login'); 
     } 
    } 

    /** 
    * Load the main view with all the current model model's data. 
    * @return void 
    */ 
    public function index() { 

     //all the posts sent by the view 
     $search_string = $this->input->post('search_string'); 
     $order = $this->input->post('order'); 
     $order_type = $this->input->post('order_type'); 

     //pagination settings 
     $config['per_page'] = 5; 

     $config['base_url'] = base_url() . 'admin/clients'; 
     $config['use_page_numbers'] = TRUE; 
     $config['num_links'] = 20; 
     $config['full_tag_open'] = '<ul>'; 
     $config['full_tag_close'] = '</ul>'; 
     $config['num_tag_open'] = '<li>'; 
     $config['num_tag_close'] = '</li>'; 
     $config['cur_tag_open'] = '<li class="active"><a>'; 
     $config['cur_tag_close'] = '</a></li>'; 

     //limit end 
     $page = $this->uri->segment(3); 

     //math to get the initial record to be select in the database 
     $limit_end = ($page * $config['per_page']) - $config['per_page']; 
     if ($limit_end < 0) { 
      $limit_end = 0; 
     } 

     //if order type was changed 
     if ($order_type) { 
      $filter_session_data['order_type'] = $order_type; 
     } else { 
      //we have something stored in the session? 
      if ($this->session->userdata('order_type')) { 
       $order_type = $this->session->userdata('order_type'); 
      } else { 
       //if we have nothing inside session, so it's the default "Asc" 
       $order_type = 'Asc'; 
      } 
     } 
     //make the data type var avaible to our view 
     $data['order_type_selected'] = $order_type; 


     //we must avoid a page reload with the previous session data 
     //if any filter post was sent, then it's the first time we load the content 
     //in this case we clean the session filter data 
     //if any filter post was sent but we are in some page, we must load the session data 
     //filtered && || paginated 
     if ($search_string !== false && $order !== false || $this->uri->segment(3) == true) { 

      /* 
       The comments here are the same for line 79 until 99 

       if post is not null, we store it in session data array 
       if is null, we use the session data already stored 
       we save order into the the var to load the view with the param already selected 
      */ 
      if ($search_string) { 
       $filter_session_data['search_string_selected'] = $search_string; 
      } else { 
       $search_string = $this->session->userdata('search_string_selected'); 
      } 
      $data['search_string_selected'] = $search_string; 

      if ($order) { 
       $filter_session_data['order'] = $order; 
      } else { 
       $order = $this->session->userdata('order'); 
      } 
      $data['order'] = $order; 

      //save session data into the session 
      if (isset($filter_session_data)) { 
       $this->session->set_userdata($filter_session_data); 
      } 

      //fetch sql data into arrays 
      $data['count_products'] = $this->admin_client_model->count_clients($search_string, $order); 
      $config['total_rows'] = $data['count_products']; 

      //fetch sql data into arrays 
      if ($search_string) { 
       if ($order) { 
        $data['manufacturers'] = $this->admin_client_model->get_clients($search_string, $order, $order_type, $config['per_page'], $limit_end); 
       } else { 
        $data['manufacturers'] = $this->admin_client_model->get_clients($search_string, '', $order_type, $config['per_page'], $limit_end); 
       } 
      } else { 
       if ($order) { 
        $data['manufacturers'] = $this->admin_client_model->get_clients('', $order, $order_type, $config['per_page'], $limit_end); 
       } else { 
        $data['manufacturers'] = $this->admin_client_model->get_clients('', '', $order_type, $config['per_page'], $limit_end); 
       } 
      } 
     } else { 

      //clean filter data inside section 
      $filter_session_data['manufacture_selected'] = null; 
      $filter_session_data['search_string_selected'] = null; 
      $filter_session_data['order'] = null; 
      $filter_session_data['order_type'] = null; 
      $this->session->set_userdata($filter_session_data); 

      //pre selected options 
      $data['search_string_selected'] = ''; 
      $data['order'] = 'id'; 

      //fetch sql data into arrays 
      $data['count_products'] = $this->admin_client_model->count_clients(); 
      $data['manufacturers'] = $this->admin_client_model->get_clients('', '', $order_type, $config['per_page'], $limit_end); 
      $config['total_rows'] = $data['count_products']; 
     }//!isset($search_string) && !isset($order) 
     //initializate the panination helper 
     $this->pagination->initialize($config); 

     //load the view 
     $data['main_content'] = 'admin/clients/list'; 
     $this->load->view('templates/template', $data); 
    } 

//index 

    public function add() { 
     //if save button was clicked, get the data sent via post 
     if ($this->input->server('REQUEST_METHOD') === 'POST') { 


     $config['upload_path'] ='public/images/'; 
     $config['allowed_types'] = 'gif|jpg|png|jpeg'; 
     $config['max_size'] = '100'; 
     $config['max_width'] = '1024'; 
     $config['max_height'] = '768'; 

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

      //form validation 
      $this->form_validation->set_rules('client_name', 'client_name', 'required'); 
      $clientLogo='image'; 
      $this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>'); 


      //if the form has passed through the validation 
      if ($this->form_validation->run()) { 

       if (!$this->upload->do_upload($clientLogo)) { 
        $error = array('error' => $this->upload->display_errors('<p>', '</p>')); 
        print_r($error); 
       }else { 
        //$data = array('upload_data' => $this->upload->data()); 
        //print_r($data); 
        $uploadedImg=$this->upload->data(); 
        $data_to_store = array(
         'client_name' => $this->input->post('client_name'), 
         'client_logo'=> $uploadedImg['client_name'] 
        ); 
       } 
       //if the insert has returned true then we show the flash message 
       if ($this->admin_client_model->store_clients($data_to_store)) { 
        $data['flash_message'] = TRUE; 
       } else { 
        $data['flash_message'] = FALSE; 
       } 
      } 
     } 
     //load the view 
     $data['main_content'] = 'admin/clients/add'; 
     $this->load->view('templates/template', $data); 
    } 

    /** 
    * Update item by his id 
    * @return void 
    */ 
    public function update() { 
     //product id 
     $id = $this->uri->segment(4); 

     //if save button was clicked, get the data sent via post 
     if ($this->input->server('REQUEST_METHOD') === 'POST') { 
      //form validation 
      $this->form_validation->set_rules('client_name', 'client_name', 'required'); 
      if (empty($_FILES['clientLogo']['name'])){ 
       $this->form_validation->set_rules('clientLogo', 'Client Logo', 'required'); 
      } 
      $this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>'); 
      //if the form has passed through the validation 
      if ($this->form_validation->run()) { 

       $data_to_store = array(
        'client_name' => $this->input->post('client_name'), 
        'client_logo'=>self::do_upload($_FILES['clientLogo']['name']) 
       ); 
       //if the insert has returned true then we show the flash message 
       if ($this->admin_client_model->update_clients($id, $data_to_store) == TRUE) { 
        $this->session->set_flashdata('flash_message', 'updated'); 
       } else { 
        $this->session->set_flashdata('flash_message', 'not_updated'); 
       } 
       redirect('admin/clients/update/' . $id . ''); 
      }//validation run 
     } 

     //if we are updating, and the data did not pass trough the validation 
     //the code below wel reload the current data 
     //product data 
     $data['manufacture'] = $this->admin_client_model->get_client_by_id($id); 
     //load the view 
     $data['main_content'] = 'admin/clients/edit'; 
     $this->load->view('templates/template', $data); 
    } 

//update 

    /** 
    * Delete product by his id 
    * @return void 
    */ 
    public function delete() { 
     //product id 
     $id = $this->uri->segment(4); 
     $this->admin_client_model->delete_clients($id); 
     redirect('admin/clients'); 
    } 

//edit 


} 

내 htaccess로 코드, 응답을 이해할 수있을 것이다.

$route['admin/clients/update/(:any)'] = 'admin_clients/update/$1'; $route['admin/clients/delete/(:any)'] = 'admin_clients/delete/$1'; $route['admin/clients/update'] = 'admin_clients/update'; $route['admin/clients/add'] = 'admin_clients/add'; $route['admin/clients/(:any)'] = 'admin_clients/index/$1'; //$1 = page number $route['admin/clients'] = 'admin_clients/index';

+0

종료 버튼을 눌러 컨트롤러를 확인 했습니까? 또한 뷰 파일을로드 했습니까? – Gautam3164

+0

컨트롤러 파일도 붙이십시오. – Gautam3164

+0

컨트롤러 파일을 붙여 넣었는지 확인하십시오. –

답변

0

는 다음의 .htaccess를 사용하여 주셔서 감사합니다 :

public function update ($ id = null)

이렇게하면 함수에 값 또는 null을 전달할 수 있으며 경로와 함께 사용할 수 있습니다.

그런 다음이를 삭제해야합니다 :

//product id 
$id = $this->uri->segment(4); 
+0

코드를 시도하고로드했을 때 홈페이지 URL없이 (index.php) 그주는 나를 찾을 수 없습니다 오류가 발생했습니다. –

+0

서버에서 mod_rewrite를 활성화 했습니까? 예, 다음 코드는 RewriteBase/testing_palace/ 한다 RewriteCond $ 1 나 yours.RewriteEngine 등의 유사에 대한 –

+0

을 노력하고 있습니다^(지수 \ .PHP | 자원 | 로봇 \ .txt)로! 한다 RewriteCond % {REQUEST_FILENAME} -f RewriteCond % {REQUEST_FILENAME}! -d RewriteRule^(. *) $ index.php/$ 1 [L, QSA] –

0

@Noor Fathima : 는

+0

[ 'uri_protocol'] \t = 'REQUEST_URI'; ' –

+0

확인의 config.php 파일을 확인하고 '$의 설정 [ 'uri_protocol'] \t = 'AUTO'의 값을 변경 나에게 같은 오류가 발생하지 죄송합니다 –

+0

변경된 오류가 없습니다. –

0

가 인수를 전달하기 위해 업데이트 기능을 수정하려고 라우팅 조건을 변경하십시오

RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$index.php/$1 [L,QSA] 
+0

세그먼트 4로 시도했을 때 그 기능에 들어 가지 않았다고 생각합니다. 세그먼트없이 정상적으로 작동 했었습니다. –

+0

경로가 있다면 $ route [ 'admin/clients/update'] = 'admin_clients/update'; $ route [ 'admin/clients/update/(: any)'] = 'admin_clients/update/$ 1'; 내가 게시 한 코드와 함께 그 함수를 입력해야합니다. – Oliverb

+0

그러나 $ route [ 'admin/clients/update/(: any)'] = 'admin_clients/update/$ 1'; 먼저 경로 파일 – Oliverb

0

이 시도 :

  1. 당신의 config.php 사용 $config['base_url'] = ''//leave it blank;$config['index_page'] = ''// leave it blank;에서.

  2. <a href="'.site_url("...")을 모두 <?php echo base_url("..."); ?>으로 변경하십시오.

  3. site_url()을 사용하는 모든 링크는 base_url()으로 변경됩니다.

작동하는지 확인하십시오. 어쩌면 config.php도 제공 할 수 있으므로 더 많이 디버깅 할 수 있습니다.

관련 문제