php – Codeigniter URI类如何使用 – 连字符而不是_下划线?

栏目: PHP · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/30692283/codeigniter-uri-class-how-can-i-use-hyphen-instead-underscore
我尝试使用 – 连字符创建一些控制器,模型和视图,但我总是得到 PHP

错误,所以我现在使用下划线.

它可能有url – 在codeigniter中连字符?

我的代码:

/控制器:

<?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);


    }

}

/楷模:

<?php 
class artist_model extends CI_Model {
    function getAll(){

        $q  = $this->db->query("SELECT artist_discography,artist_name from music");

        if($q->num_rows() > 0) {

            foreach ($q->result() as $row) {
                $data [] = $row;
            }
            return $data;
        }

    }
}

是的你可以.

通常CI会生成类似于base_url / Controller_name / Method_name的url.

如您所知,控制器名称和方法名称不能包含“ – ”(连字符),因此您无法更改其名称.

你能做什么是使用路由器显示正确的控制器与相应的URL.

就像你可以在config / routes.php上编写这段代码一样

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

如果你的链接是http:// localhost:8888 / ci / index.php / get-artist-discography / artist-name,这将执行你的get_artist_discography控制器和artist_name方法

您可以了解有关 URI Routing at CI docs 的更多信息

翻译自:https://stackoverflow.com/questions/30692283/codeigniter-uri-class-how-can-i-use-hyphen-instead-underscore


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

超简单!一学就懂的互联网金融

超简单!一学就懂的互联网金融

视觉图文 / 人民邮电出版社 / 2015-2-1 / 45.00元

零基础、全图解,通过130多个精辟的知识点、220多张通俗易懂的逻辑图表,让您一书在手,即可彻底看懂、玩转互联网金融从菜鸟成为达人,从新手成为互联网金融高手! 本书主要特色:最简洁的版式+最直观的图解+最实用的内容。 本书细节特色:10章专题内容详解+80多个特别提醒奉献+130多个知识点讲解+220多张图片全程图解,深度剖析互联网金融的精华之处,帮助读者在最短的时间内掌握互联网金融知......一起来看看 《超简单!一学就懂的互联网金融》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具