Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Method request #116

Open
agregator123 opened this issue Mar 28, 2017 · 2 comments
Open

Method request #116

agregator123 opened this issue Mar 28, 2017 · 2 comments

Comments

@agregator123
Copy link

agregator123 commented Mar 28, 2017

I want to submit a nice request ( i think )
For now in methods we have:
GET POST etc... i want to be added one more "XHR" or "Ajax" and this one can be accepted only ajax requests.
Now my controllers with ajax must be like this:

 if(parent::is_ajax()) {
 //my code
}

is_ajax function is:

  public function is_ajax() {
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
  }

I need this to be added and my routers will be:

$collection->attachRoute(new PHPRouter\Route('/', [
    '_controller' => 'App\Controllers\Index::Index',
    'methods' => 'AJAX',
    'parameters'=> ['template_file'=>'index'],
]));

instead

$collection->attachRoute(new PHPRouter\Route('/', [
    '_controller' => 'App\Controllers\Index::Index',
    'methods' => 'GET',
    'parameters'=> ['template_file'=>'index'],
]));

is this possible ?

@lpotherat
Copy link
Contributor

In my opinion AJAX cannot be a HTTP Method, since you can use any of POST,GET,DELETE,PUT,... method in your ajax call, PHP-Router would not be able to distinguish POST or DELETE for example.

I think AJAX should be included in another set of caller constraint, wich could be :

a route could be then : method: POST, XHR only, HTTPS only

@agregator123
Copy link
Author

This will be cool. I'm waiting for update :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants