Welcome Guest, Not a member yet? Register   Sign In
Issue with the controller arguement
#11

(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??
Reply
#12

(This post was last modified: 07-12-2018, 07:48 AM by kilishan.)

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.
Reply
#13

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
Reply
#14

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.
Reply
#15

ok fair
Reply
#16

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

Kudos, it's working as expected.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB