Welcome Guest, Not a member yet? Register   Sign In
CI4 Beta 1: function _remap not works properly
#1
Bug 

my english is not the best.

in Codeigniter 3 I do:

URL:
/test/parameter1/parameter2/<parameterN>

CI3
called class: Test 
called method:  _remap (I have it function declared).

in Codeigniter 3 all works ok.

but in Codeigniter 4,

with URL:
/test
CI4 call method _remap, woks ok.

but with URL:
/test/parameter1
or URL 
/test/parameter1/parameter2/<parameterN>

show error: ReflectionException "Method App\Controllers\Test::parameter1() does not exist"

-----

Details:
- No setting route additional.
- I try wihtout function index, but it does not affect.

PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Test extends Controller
{
    public function 
index()
    {
        echo 
"Test/index";
    }
    
//--------------------------------------------------------------------
    
public function _remap($method)
    {
        echo 
"Test/remap - {$method}";
    }
    
//--------------------------------------------------------------------




excuse my english, I appreciate the help. thanks!!

Attached Files Thumbnail(s)
   
Reply
#2

I'm having the same issue.

My approach is to "fool" it by placing a dummy function if I'm not messing with Route

Code:
public function parameter1()
{
    // placeholder
}

Anyone has a better idea?

(03-25-2019, 10:12 PM)hlmqz Wrote: my english is not the best.

in Codeigniter 3 I do:

URL:
/test/parameter1/parameter2/<parameterN>

CI3
called class: Test 
called method:  _remap (I have it function declared).

in Codeigniter 3 all works ok.

but in Codeigniter 4,

with URL:
/test
CI4 call method _remap, woks ok.

but with URL:
/test/parameter1
or URL 
/test/parameter1/parameter2/<parameterN>

show error: ReflectionException "Method App\Controllers\Test::parameter1() does not exist"

-----

Details:
- No setting route additional.
- I try wihtout function index, but it does not affect.

PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Test extends Controller
{
    public function 
index()
    {
        echo 
"Test/index";
    }
    
//--------------------------------------------------------------------
    
public function _remap($method)
    {
        echo 
"Test/remap - {$method}";
    }
    
//--------------------------------------------------------------------




excuse my english, I appreciate the help. thanks!!
Reply
#3

See https://github.com/codeigniter4/CodeIgni...ssues/1928
Your controllers are supposed to have an index() method.
Reply
#4

Thanks for the speedy reply. Actually, I do have an index() method

So, I just pulled down CI 4.0.0-rc.1

This is my code

Code:
<?php namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        return view('welcome_message');
    }

    public function go_back()
    {
        echo "gone home";
    }
   
    public function _remap($methodName, ...$params)
    {
        $functionName = 'go_' . $methodName;
        if (method_exists($this, $functionName)) {
                return $this->$functionName(...$params);
        }
        throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
    }

    //--------------------------------------------------------------------
}

Anything else I've missed?

THanks!

jUstin
Reply
#5

@justin It looks like your _remap purposefully throws an exception if an unrecognozed method is called.
How is this incorrect behavior? It sounds like _remap is doing just what your code says it should.
Reply
#6

Hi Here,

I thought about that, but the error I'm getting is not the 404, but the one shared by the original author of this post.

Let me simplify my example to make it more straight forward.

Code:
<?php namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        return view('welcome_message');
    }

    public function go_back()
    {
        echo "gone home";
    }
   
    public function _remap($methodName, ...$params)
    {
        return $this->go_back(...$params);
    }

    //--------------------------------------------------------------------
}

And I tried to access a method that is not there, i.e. /home/go. The _remap should kick in and call $this->go_back()

But, that's not happening...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB