Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter URI类如何使用–;用连字符代替下划线?_Php_Codeigniter_Url - Fatal编程技术网

Php Codeigniter URI类如何使用–;用连字符代替下划线?

Php Codeigniter URI类如何使用–;用连字符代替下划线?,php,codeigniter,url,Php,Codeigniter,Url,我尝试使用-连字符创建一些控制器、模型和视图,但我总是遇到php错误,所以我现在使用下划线 所以我的url是: 我想是这样的: 在codeigniter中可能有带连字符的URL吗 我的代码: /控制器: <?php include (APPPATH.'/libraries/REST_Controller.php'); class get_artist_discography extends REST_Controller { function artist_name

我尝试使用-连字符创建一些控制器、模型和视图,但我总是遇到php错误,所以我现在使用下划线

所以我的url是:

我想是这样的:

在codeigniter中可能有带连字符的URL吗

我的代码:

/控制器:

    <?php 
include (APPPATH.'/libraries/REST_Controller.php');
class get_artist_discography extends REST_Controller {

    function artist_name_get(){

    $data = new stdClass();
    $this->load->model('artist_model');
    $data = $this->artist_model->getAll();$this->response($data, 200);


    }

}
是的,你可以

通常CI生成的url类似于此基本url/控制器名称/方法名称

正如您所知,控制器名称和方法名称不能包含“-”(连字符),因此您不能更改它们的名称

你能做的就是用路由器显示正确的控制器和相应的url

您可以在config/routes.php中编写此代码

$route['get-artist-discography/artist-name'] ='get_artist_discography/artist_name';
$route['translate_uri_dashes'] = TRUE;
如果链接为
http://localhost:8888/ci/index.php/get-艺术家唱片/艺术家姓名


如果您使用Codeigniter 3打开config/routes.php,您可以了解有关

的更多信息

$route['get-artist-discography/artist-name'] ='get_artist_discography/artist_name';
$route['translate_uri_dashes'] = TRUE;

是,如果您的控制器和方法名称与URL相同,仅与连字符和下划线不同,并且您使用CI-3,则可以使用此解决方案。使用$route['translate\u uri\u dashes']=TRUE;改为在config/routes.php中。您不必为每个控制器添加路由。