2017-05-31 79 views
0

我使用"<a href='".base_url() ."auth/confirmNewUser/".$username."' class='btn btn-sm'>Create&nbsp;Account</a>";生成一個URL,然後映射到代碼點火器

function confirmNewUser() { 

    $newuser =$this->uri->segment(3); 

,我現在已經是這個工程的超過一個特定的文本參數(nicoe)其他一切問題的特定參數返回404總是返回404錯誤。所以基本上它根本沒有達到該方法。我很有智慧。任何調試建議都會非常有幫助。 感謝

回答

2

我想你需要創建一個路由

$route['auth/confirmNewUser/(:any)'] = 'auth/confirmNewUser/$1'; 

https://www.codeigniter.com/user_guide/general/routing.html

https://www.codeigniter.com/user_guide/general/routing.html#examples

爲什麼它可能無法正常工作的另一個原因是因爲你沒有一個htaccess的適合你的主目錄

如何刪除index.php

https://github.com/wolfgang1983/htaccess_for_codeigniter

確保控制器和類名的文件名只有首字母大寫休息小寫。

名控制器/ Auth.php

<?php 

class Auth extends CI_Controller { 

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

    public function confirmNewUser($username) { 
     echo $username; // Testing 

     $data['username'] = $username; 

     $this->load->view('some_view', $data); 
    } 

} 

還要確保基本URL設置

$config['base_url'] = 'http://localhost/yourproject/'; 

或者,如果活DOMIAN例如

$config['base_url'] = 'http://www.example.com/'; 
+0

同樣的問題。我有的問題不是它沒有路由。它將路由所有其他請求,但返回404用於該特定參數。這是非常奇特的。 – bidhan

+0

@bidhan是否在url中使用index.php嘗試使用htaccess的'http:// localhost/yourproject/index.php/auth/confirmNewUser/someusername' – user4419336

+0

。這個問題有什麼想法?請記住這是針對一個特定的參數 – bidhan