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

The isAJAX method does not exist in filters #3604

Closed
luispastendev opened this issue Sep 4, 2020 · 4 comments
Closed

The isAJAX method does not exist in filters #3604

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

Comments

@luispastendev
Copy link

I need to do a comparison inside a filter to know if $request is of type ajax. but it seems that the method loaded in the callback is not there:

public function before(RequestInterface $request, $args = null){
    if($request->isAJAX()){ // <- not defined method
          ......
    }
}

I think that method should be inside the request since until now it could only be solved in the following way:

if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){
    ....
}

greetings

@MGatner
Copy link
Member

MGatner commented Sep 5, 2020

The method definitely exists, IncomingRequest line 279:

public function isAJAX(): bool

You may have something wrong with your installation, or perhaps using a custom Request object? Since Filters receive RequestInterface $request it isn't necessarily an IncomingRequest. Add this to your filter to see what kind of object you're actually getting: dd($request);

@MGatner MGatner added bug Verified issues on the current code behavior or pull requests that will fix them investigating waiting for info Issues or pull requests that need further clarification from the author labels Sep 5, 2020
@samsonasik
Copy link
Member

I can't reproduce, I used it in https://github.com/samsonasik/ci4-vue project and working OK:

https://github.com/samsonasik/ci4-vue/blob/7572347636babc30cadb4ea91cca6e6c7e3508d5/app/Filters/LayoutUsage.php#L11-L17

@michalsn
Copy link
Member

michalsn commented Sep 6, 2020

I couldn't reproduce it either. What version of CI are you using?

@luispastendev
Copy link
Author

OMG A thousand apologies for raising this stupid issue, I was distracted, it works correctly but it seems to have been some problem with the linter I'm using! I close the issue :(

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 investigating waiting for info Issues or pull requests that need further clarification from the author
Projects
None yet
Development

No branches or pull requests

4 participants