我使用下面的代碼爲我的網站,但它顯示我如何發送ID到控制器笨
404:找不到網頁。
路由
$route['class_name/function_name/(:num)'] = 'class_name/function_name/$1';
控制器。
public function function_name($Id)
{
print_r($Id); exit;
}
我使用下面的代碼爲我的網站,但它顯示我如何發送ID到控制器笨
404:找不到網頁。
路由
$route['class_name/function_name/(:num)'] = 'class_name/function_name/$1';
控制器。
public function function_name($Id)
{
print_r($Id); exit;
}
使用URI來從URL中提取ID: 以下是在文檔的鏈接:http://www.codeigniter.com/userguide2/libraries/uri.html
我有可能創建一個簡單的它可以幫助你
這是我的控制器welcome.php從codeigniter新鮮
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->view('welcome_message');
}
public function test1($ID) {
echo $ID;
}
public function test2($ID, $ID2) {
var_dump($ID, $ID2);
}
public function test() {
echo 'test';
}
}
,這裏是我的路線
$route['default_controller'] = 'welcome';
$route['welcome/test1/(:num)'] = 'welcome/test1/$1';
$route['welcome/test/(:num)/(:num)'] = 'welcome/test/$1/$2';
例如訪問它,如果工作
https://192.168.248.209/stackoverflow/welcome/test2/1/3 https://192.168.248.209/stackoverflow/welcome/test1/1
這個根據你的服務器是動態執行
感謝您的回覆。我在我的默認控制器中使用了您的代碼,但無法正常工作。有什麼幫助嗎? 。配置文件中是否有任何設置? – Fadu
@Fadu,htaccess和mod_rewrite你啓用它? –
並從你得到的地方'$ Id' –
不知道我在嘗試使用google搜索。我也使用了$ this-> uri-> segment(3),但他們沒有給我編號 – Fadu
您正在使用的東西類似於http://example.com/class_name/function_name/3的URL,還是你使用不同的格式? – gabe3886