Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Route options filter didn't working #2654

Closed
gaibz opened this issue Mar 1, 2020 · 7 comments
Closed

Bug: Route options filter didn't working #2654

gaibz opened this issue Mar 1, 2020 · 7 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them waiting for info Issues or pull requests that need further clarification from the author

Comments

@gaibz
Copy link

gaibz commented Mar 1, 2020

I think I found a bug in Route options Filter ..

Using codeigniter 4.0 latest release from composer repository ..

I have the following config on my routes.php

$routes->post('closed/auth', 'Closed\Auth::auth', ['filter'=>'coba']);

and have the following config on my filters.php

public $aliases = [ 'coba' => \App\Filters\CobaFilter::class ];

and then on my CobaFilter.php under Filters folder

<?php

namespace App\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

class CobaFilter implements FilterInterface
{
public function before(RequestInterface $request)
{
die($request); // not executed
}

public function after(RequestInterface $request, ResponseInterface $response)
{
return $response;
}
}`

But if i have group routes config it just work .. i.e (routes.php):

$routes->group('closed', ['filter'=>'coba'], function($routes)
{
$routes->post('auth', 'Closed\Auth::auth');
});

I'm not quiet sure if this is a bug or just my mistake ..
i just follow the documentation page : https://codeigniter4.github.io/userguide/incoming/routing.html#applying-filters

Hope you guys find a solution for this ..

@gaibz gaibz added the bug Verified issues on the current code behavior or pull requests that will fix them label Mar 1, 2020
@MGatner
Copy link
Member

MGatner commented Mar 1, 2020

Does closed/auth actually route in your first example, and just the filter doesn’t run? Can you also turn off autorouting to be sure it’s matching your definition?

@michalsn
Copy link
Member

michalsn commented Mar 1, 2020

I couldn't recreate this bug. The filters in both cases work for me just fine.

Are you sure you're testing this with post request?

@gaibz
Copy link
Author

gaibz commented Mar 2, 2020

Does closed/auth actually route in your first example, and just the filter doesn’t run? Can you also turn off autorouting to be sure it’s matching your definition?

yes, closed/auth is routed to my controller perfectly with post request ..
it just the filter didn't work ..
in the example above I try to die($request) or die(var_export($request) execution to see if filter work before hitting the controller .. but before() function on my Filter didn't triggering at all ..

well i'll try to turn off autorouting to see if it working ..

@gaibz
Copy link
Author

gaibz commented Mar 2, 2020

I couldn't recreate this bug. The filters in both cases work for me just fine.

Are you sure you're testing this with post request?

yep, i am pretty sure that i send post request with my Postman ..

@bangbangda
Copy link
Contributor

bangbangda commented Mar 13, 2020

@gaibz
CobaFilter is run. Replace die($request); with var_dump($request);exit;. Try again.

public function before(RequestInterface $request)
{
     var_dump($request);exit;
}

die($request); will only exit and will not output anything.
Do you mean that the program has not exited?

@lonnieezell lonnieezell added the waiting for info Issues or pull requests that need further clarification from the author label Mar 16, 2020
@gaibz
Copy link
Author

gaibz commented Mar 30, 2020

@gaibz
CobaFilter is run. Replace die($request); with var_dump($request);exit;. Try again.

public function before(RequestInterface $request)
{
     var_dump($request);exit;
}

die($request); will only exit and will not output anything.
Do you mean that the program has not exited?

yes i know die($request) will only exit and not output anything ..
but the problem is die() never firing in my case .. the script execution didn't stop at all ..

@gaibz
Copy link
Author

gaibz commented Mar 30, 2020

well, after all i guess grouping routes

$routes->group('closed', ['filter'=>'coba'], function($routes)
{
    $routes->post('auth', 'Closed\Auth::auth');
});

is the best solution that work in my case ..

Thanks all ..

@gaibz gaibz closed this as completed Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them waiting for info Issues or pull requests that need further clarification from the author
Projects
None yet
Development

No branches or pull requests

5 participants