$route['written-qb/(:any)/(:any)/(:any)']不起作用。
P粉155832941
P粉155832941 2023-07-30 19:03:57
0
1
661
<p>當我使用uri段2和3時,它可以工作,但是當我添加uri段4時,它就不起作用了。 </p><p>URL應該像這樣... http://localhost/maruf/written-qb/bcs/44th-bcs-english/how-has-the-phrase-digital-detox-been- explained-in-the-passage? </p><p>但它顯示為... http://localhost/maruf/written-qb/bcs/how-has-the-phrase-digital-detox-been-explained-in-the- passage?而且兩個URL都顯示404。 </p><p>這是我的路由設定。</p><p><br />></p>
$route['writing-qb/(:num)'] = 'writing-qb'; //作品
$route['書面qb/(:any)/(:any)'] = '書面qb/書面_qb_details/$1/$2'; //作品
$route['書面qb/(:any)/(:any)/(:any)'] = '書面qb/writing_qb_answer/$1/$2/$3'; // 不起作用</pre>
<p>我的控制器是...</p>
公用函數index(){
        
        $data['qb_list'] = $this->Question_bank_model->get_qb_with_category(FALSE);
        //頁尾數據
        $data['main_content'] = 'writing_qb';
        $this->load->view('include/template',$data);
    } // 運作正常
    
    公用函數 write_qb_details($category, $slug = NULL){
        
        $config['uri_segment'] = 2;
        $slug = $this->uri->segment(3);
        //數據
        $data['qb_list'] = $this->Question_bank_model->get_qb_with_category(FALSE);
        $data['qb_info'] = $this->Question_bank_model->get_qb_details($slug, $config['uri_segment']);
        如果(空($data['qb_info'])){
            顯示_404();
        }
        $data['url_slug'] = $data['qb_info']['qb_exam_slug'];
        $data['meta_title'] = $data['qb_info']['qb_exam'];
        $data['meta_description'] = $data['qb_info']['qb_exam_post_meta'];
        $data['meta_keywords'] = $data['qb_info']['qb_exam_post_tags'];
        //看法
        $data['main_content'] = 'writing_qb_details';
        $this->load->view('include/template',$data);
    } // 運作正常
    
    公用函數 write_qb_answer($slug = NULL, $slug2 = NULL){
        
        $config['uri_segment'] = 2;
        $slug = $this->uri->segment(3);
        $slug2 = $this->uri->segment(4);
        //數據
        $data['qb_info'] = $this->Question_bank_model->get_qb_answer_details($slug, $slug2, $config['uri_segment']);
        如果(空($data['qb_info'])){
            顯示_404();
        }
        $data['url_slug'] = $data['qb_info']['qb_exam_question_slug'];
        $data['meta_title'] = $data['qb_info']['qb_exam_question'];
        $data['meta_description'] = $data['qb_info']['qb_exam_answer_meta'];
        $data['meta_keywords'] = $data['qb_info']['qb_exam_answer_tags'];
        //看法
        $data['main_content'] = '答案';
        $this->load->view('include/template',$data);
    }// 它不起作用</pre>
<p>而我的模型是...</p>
<pre class="brush:php;toolbar:false;">公用函數 get_qb_details($slug = FALSE){
            
            如果($slug === FALSE){
                $this->db->order_by('qb_post.qb_exam_slug', 'DESC');
                $this->db->join('qb_category', 'qb_category.qb_category_name_slug = qb_post.qb_category_name_slug');
                $this->db->where('qb_exam_active',1);
                $query = $this->db->get('qb_post');
                返回 $query->result_array();
            }
        
            $query = $this->db->get_where('qb_post', array('qb_exam_slug' => $slug));
            返回 $query->row_array();
        }
        公用函數 get_qb_answer_details($slug2 = FALSE){
            
            if($slug2 === FALSE){
                $this->db->where('qb_exam_answer_active',1);
                $query = $this->db->get('qb_exam_ans');
                返回 $query->result_array();
            }
        
            $query = $this->db->get_where('qb_exam_ans', array('qb_exam_question_slug' => $slug2));
            返回 $query->row_array();
        }</pre>
<p>在控制器"writing_qb_answer"中,以及在路由$route['writing-qb/(:any)/(:any)/(:any)'] = 'writing-qb/writing_qb_answer/$1/$2 /$3';中,停用。它顯示404錯誤。</p>            
P粉155832941
P粉155832941

全部回覆(1)
P粉323224129

您的路由重疊了。

$route['written-qb/(:num)'] = 'written-qb';  //works
$route['written-qb/(:any)/(:any)'] = 'written-qb/written_qb_details//';  //works
$route['written-qb/(:any)/(:any)/(:any)'] = 'written-qb/written_qb_answer///';  //does not work

請檢視文件中的註解:
註解1:
註解2:
註解3:

路由不是篩選器,當你使用(:any)時,它表示任何內容!為什麼第一個和第二個有效?因為您首先檢查是否為數字,對於第一個未捕獲的任何內容都會被第二個捕獲,這意味著第三個永遠不起作用。這就像是如果...否則...而不是如果...否則如果...否則...

#
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板