用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1366|回复: 5
收起左侧

[版本 4.x] controller的 _remap 似乎失效?

[复制链接]
发表于 2019-2-20 13:21:13 | 显示全部楼层 |阅读模式
我在App\Controllers\wheels建立一支controller: care.php,
简单测试_remap,代码如下,
假设网址为 127.0.0.1/myproject/wheels/care/a1,结果会出现 a1,
假设网址为 127.0.0.1/myproject/wheels/care/bb123,结果会出现 Method App\Controllers\wheels\Care::bb123() does not exis,
并没有如我预期导向contentProcess函式,
请教我哪边写错了呢? 谢谢


PHP复制代码
 
 
namespace App\Controllers\wheels;
 
use CodeIgniter\Controller;
 
class Care extends Controller {
 
    public function _remap($method, ...$params) {
        if (method_exists($this, $method)) {
            return $this->$method();
        }else{
             return $this->contentProcess();
        }
    }
 
    protected function contentProcess() {
        echo 'contentProcess';
    }
 
    protected function a1() {
        echo "a1";
    }
 
}
 
 
 
复制代码


发表于 2019-2-20 16:38:33 | 显示全部楼层
本帖最后由 燃雲 于 2019-2-20 16:40 编辑
PHP复制代码
 
public function _remap($method, ...$params)
{
        $method = 'process_'.$method;
        if (method_exists($this, $method))
        {
                return $this->$method(...$params);
        }
        show_404();
}
 
复制代码

 楼主| 发表于 2019-2-21 08:37:22 | 显示全部楼层
谢谢你的协助,但这不是答案
发表于 2019-2-22 17:41:01 | 显示全部楼层
rfrkk 发表于 2019-2-21 08:37
谢谢你的协助,但这不是答案
PHP复制代码
 
public function _remap($method, ...$params)
{
        $method = 'process_'.$method;  // <-这不是答案?
        if ([url=http://www.php.net/method_exists]method_exists[/url]($this, $method))
        {
                return $this->$method(...$params);
        }
        show_404();
}
 
复制代码


发表于 2019-2-22 18:53:31 | 显示全部楼层
看起来没问题,更新一下 CI4 到最新版试试?
 楼主| 发表于 2019-2-23 09:21:08 | 显示全部楼层
我發現問題是在 ci debug tool 的route.php

我打包成zip 下載點


https://drive.google.com/file/d/1odfEF8Pflvfxa0Fgsx05SwfGkibBoTDW/view

本版积分规则