如何在代码点火器3中将GET方法形式的url更改为斜杠


How to change url of GET method form to slashes in codeigniter 3

我找不到问题的解决方案,如果我的问题重复,请提供参考链接。所以我需要你的帮助。举个例子:

localhost/ci/index.php/search/?song=sheila+开启+7

成为

localhost/ci/index.php/search/sheila_on_7

localhost/ci/index.php/search/song/sheila_on_7

谢谢。

CodeIgniter可选地支持此功能,该功能可以在application/config.php文件中启用。如果你打开你的配置文件,你会看到这些项目:

$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

如果将"enable_query_strings"更改为TRUE,此功能将变为活动状态。然后,您的控制器和功能将可以使用您设置的"触发器"字来调用控制器和方法:

index.php?c=controller&m=method

更多信息可以在CodeIgniter URL用户指南中找到

您必须将表单方法从GET更改为POST。Inflector助手有一个可以使用的函数,也可以使用str_replace()PHP函数。比这样的东西:

<?php defined('BASEPATH') OR exit('Not your cup of tea');
class Search extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('inflector');
    }
    public function song($song)
    {
        $song = underscore($this->input->post('song'));//name of field in view which becomes sheila_on_7
        //use variable for DB search or what ever you need
        //$data['song'] = $this->Song_m->get('title', $this->input->post('song'));
        //$this->load->view('search', $data);
    }
}