DooPHP IRC channel


ajax route

Discussion about new desired features.

ajax route

Postby coder » Sat Jan 14, 2012 6:30 am

Hi,

it would be nice to route ajax reqs directly.

I make a lot of

if ($this->isAJAX()){
// do ajax stuff
}
else {
// do other stuff
}

It would be nice to do this automatically, like:

$route['ajax']['/job/add'] = array('MyController', 'addJobViaAjax');
$route['post']['/job/add'] = array('MyController', 'addJobViaPost');

Would this be possible to integrate in the next release?

Thx,
coder
coder
 
Posts: 3
Joined: Sat Jan 14, 2012 6:24 am

Re: ajax route

Postby roman » Sun Jan 15, 2012 1:07 am

AJAX requests can be of two types: GET and POST, so your sample routes seem problematic considering that.

The framework supports specifying file extension in routes. (See http://doophp.com/doc/guide/basic/routes.) Maybe that will work for you?
roman
 
Posts: 442
Joined: Sat Aug 01, 2009 8:31 pm

Re: ajax route

Postby coder » Sun Jan 15, 2012 10:55 am

Hi roman,

i know that this could be problematic, so for another try:

I know that there is a catchall param to a route like this:

$route['*']['catchall']['/public/doStuff'] = array('PublicController', 'index');

So for an ajax req it could be a solution to put something like this in the routes:

$route['*']['ajax']['/public/doAjaxStuff'] = array('PublicController', 'ajaxIndex');
$route['get']['ajax']['/public/doAjaxGetStuff'] = array('PublicController', 'ajaxGetIndex');
$route['post']['ajax']['/public/doAjaxPostStuff'] = array('PublicController', 'ajaxPostIndex');

That could be a solution and not so hard to implement.

Thank you...
coder
 
Posts: 3
Joined: Sat Jan 14, 2012 6:24 am

Re: ajax route

Postby coder » Sun Jan 15, 2012 11:35 am

Hi roman,

the file extension param is not a solution to me because i've to rewrite on the client side the request:

Normal req: /do/some/stuff
Ajax: /do/some/stuff.ajax

The current way is the route "/do/some/stuff" and in the method of the controller i have to check if the req is an ajax req.
In every method i have a "if ($this->isAJAX())..."... not so nice.

So it would be a really good solution to have a

$route['*']['ajax']['/do/some/stuff']=array('myController', 'doSomeAjaxStuff');
$route['*']['/do/some/stuff']=array('myController', 'doSomeNormalStuff');

Thx,
coder
coder
 
Posts: 3
Joined: Sat Jan 14, 2012 6:24 am

Re: ajax route

Postby roman » Sun Jan 15, 2012 6:22 pm

I agree with you that this would be useful. I hope that Leng or Richard will add this to their to-do list.
roman
 
Posts: 442
Joined: Sat Aug 01, 2009 8:31 pm


Return to Features Request

Who is online

Users browsing this forum: No registered users and 1 guest