【问题标题】:Can't call method from URL when super class is REST_Controller, codeigniter超类为 REST_Controller、codeigniter 时无法从 URL 调用方法
【发布时间】:2014-09-28 16:30:50
【问题描述】:

我想从浏览器运行 URL 并获取位于我的项目之外的文件内容,例如:/home/fessy/file.txt

我使用 codeigniter 和学说。

我有一个方法:

class Api extends REST_Controller {

// ....

public function get_file_content_get(){
   var_dump(array('ftp_path' => $this->uri->segments)); 

       $name      = $this->uri->segment(3);
       $rootPath = $this->uri->segment(4);

       $file = file_get_contents("$rootPath/$name.txt", FILE_USE_INCLUDE_PATH);

     // $this->_response('success', array('file_contents' => $file));       
}

所以我将我的 URL 生成为:

site.com/index.php/api/get_file_content_get/118130/%2Fhome%2Ffessy%2Ffile.txt

但我得到一个错误:

<xml>
   <status/>
   <error>Unknown method.</error>
</xml>

当我将超类从REST_Controller 更改为CI_Controller 时,我成功调用了get_file_content_get 方法。

我无法让site.com/index.php/api/get_file_content_get/ 调用index()

我做错了什么?

谢谢,

【问题讨论】:

    标签: codeigniter doctrine


    【解决方案1】:

    发现问题:

    我需要删除 _get 后缀,因为 Doctrine 使用这个后缀作为 GET 指示符

    改为:

    site.com/index.php/api/get_file_content_get/118130/%2Fhome%2Ffessy%2Ffile.txt
    

    应该是:

    site.com/index.php/api/get_file_content/118130/%2Fhome%2Ffessy%2Ffile.txt
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 2023-03-11
      • 1970-01-01
      • 2014-01-15
      • 2017-05-20
      • 2012-04-18
      相关资源
      最近更新 更多