gpt4 book ai didi

php - 在 CodeIgniter 中将参数传递给 index()

转载 作者:行者123 更新时间:2023-12-04 14:43:03 27 4
gpt4 key购买 nike

我的应用程序具有以下结构:

myapp/index.php: index page
myapp/mycont/myfunc/productID: dedicated page for product

index.php 包含打开 myapp/mycont/myfunc/productID

的链接

因此, Controller 函数定义为:

index() {...}
myfunc($id) {...}

因为,我的两个函数几乎相同,所以我想删除 myfunc() 函数并将 URL 更改为:

myapp/: index page
myapp/productID: dedicated page for product

上述两个 URL 都应该使用 index() 函数,但是如果我尝试向它传递参数,index 函数会抛出错误。

最佳答案

在 CI 中将参数传递给索引函数:

1) 您需要 indexhttp://www.example.com/search/index/search-keyword.
2) 或者你需要使用路由 $route['search/(:any)'] = 'search/index/$1';
3) 或者尝试重新映射:https://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping


编辑(样本):

$route['abc/campaigns/add_webengage_feedback_leads'] = "abc/campaigns/add_webengage_feedback_leads";
$route['abc/campaigns/add_webengage_survey_leads'] = "abc/campaigns/add_webengage_survey_leads";
$route['abc/campaigns/add_canvass_data'] = "abc/campaigns/add_canvass_data";
$route['abc/campaigns/add_connecto_data'] = "abc/campaigns/add_connecto_data";
$route['abc/campaigns/(:any)'] = "abc/campaigns/index/$1";

注意:映射到index函数的URL应该放在最后。

关于php - 在 CodeIgniter 中将参数传递给 index(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25133386/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com