CodeIgniter Forums
Issue with the controller arguement - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Issue with the controller arguement (/showthread.php?tid=71133)

Pages: 1 2


RE: Issue with the controller arguement - scalla - 07-12-2018

(07-12-2018, 06:32 AM)kilishan Wrote: And the "redirect issue" in the controller constructor isn't able to be fixed as you cannot return another object from a class constructor. You can always use filters (once investigated and fixed) or the _remap method in the controller.

mind giving a snippet??


RE: Issue with the controller arguement - kilishan - 07-12-2018

Here's a simple controller to demonstrate:

Code:
<?php namespace App\Controllers;

use CodeIgniter\Controller;

class Tests extends Controller
{
    public function _remap($method, ...$params)
    {
        if (! method_exists($this, $method))
        {
            return redirect('/tests/hidden');
        }

        $this->{$method}(...$params);
    }

    public function hidden()
    {
        echo '<h1>You found it!</h1>';
    }
}

Navigate to /tests/hidden, and the page displays like you would expect. Navigate to /tests and you will be redirected to the hidden method.

I did confirm something is going screwy with the filtering and redirects but not sure what yet. I've got some plans this evening, but hopefully will have a chance to look into it.


RE: Issue with the controller arguement - scalla - 07-12-2018

fair enough, i would test to see it out come. the filter might be could working like laravel's middleware with router, i know the codeigniter team does not intend making igniter 4 look like larvel, but the middleware thing might spice thing up


RE: Issue with the controller arguement - kilishan - 07-12-2018

I did test that controller and it worked just fine.

The filters are our version of "router middleware" that Laravel and a few other frameworks support. Because we still support the old-style auto-routing of controllers, traditional middleware like Laravel implements cannot work because the route file will not always be used. That's why we split it out to it's own file. Other than that, they are conceptually the same.


RE: Issue with the controller arguement - scalla - 07-12-2018

ok fair


RE: Issue with the controller arguement - kilishan - 07-13-2018

Ok - the redirect issue in filters should be resolved in the latest develop branch. Let me know if you still have issues with it.


RE: Issue with the controller arguement - scalla - 07-13-2018

Kudos, it's working as expected.