php - 用于将 get 参数传递给索引函数的 Codeigniter 路由

标签 php codeigniter

我有一个网址www.mywebsite.com/store/123456

其中 store 是我的 Controller 类,其中有一个索引函数,我在 store 之后获取值,即 123456。但我无法实现它。

据网上发现,我尝试将其添加到路由$route['store/(:any)'] = 'store/index';也尝试过

$route['store/(:any)'] = 'store/index/$1';

但似乎不起作用。请帮助我。

在 Controller 中索引函数是

public function index()
    {
        echo $this->uri->segment(1);
    }

但它不起作用。请帮忙

最佳答案

您正在调用 123456() 方法而不是 index() 方法,因此您会得到 CI 的 404。

最简单的方法就是使用这种路由

$route['store/(:any)'] = 'store/index/$1';

并在其顶部添加参数到您案例中的索引函数

public function index($parameter)
{

    echo $this->uri->segment(2);
}

请注意,我更改了段参数,请参阅 documentation


使用_remap()

function _remap($parameter){

   $this->index($parameter);
}

function index($p) 
{
    echo $p; //shows 123456 
}

关于php - 用于将 get 参数传递给索引函数的 Codeigniter 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27205194/

相关文章:

php - 如何使用 Codeigniter 互连三个 mysql 表

image - 有没有办法让 Codeigniter Controller 返回图像?

javascript - jQuery 在传递 POST 数据时在新选项卡中打开页面

php - MySQL/PHP 排序丹麦字母

php - ReCaptcha 不接受任何字符串

php - 将月份分成 4 份并检索每天的平均值

mysql - 查询mysql的帖子和评论系统

php - 在 codeigniter 中一次更新两个表

php - 如何删除关联数组键并添加默认数组键 PHP

php - HTML 按钮在页面刷新时移动?