• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with the controller arguement

#11
(07-12-2018, 07: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
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.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
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.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
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.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#17
Kudos, it's working as expected.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
2 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.