Welcome Guest, Not a member yet? Register   Sign In
How to use URL to define response type
#3

[eluser]MikeVrind[/eluser]
I just started working this again after a little busy period.

I have the route added to the routes file. This worked very easy!
Only I used a slightly different approach for the route:
Code:
$route['json/(:any)'] = "$1/";

I Router I then made ​​a small adjustment to determine the request method.
This gives me the opportunity to use the router for getting the requestmethod.

Code:
$this->router->requestFormat

The default value of this var is HTML, but could be set to json or something else.

Judging by your example I should build a switch in every controller? This seems a bit awkward because it goes completely against the DRY (Dont repeat yourself) principle.

I'm just still looking into the framework for the best way to implement the final step, depending on the application method, outputing the data in the correct way (As HTML or JSON string).
Because I also want to add Twig as an template parser in the framework, I'm thinking of building a custom 'Output' classe that calls Twig in case of an HTML request and used json_encode() in case of an JSON request.


Messages In This Thread
How to use URL to define response type - by El Forum - 02-09-2013, 05:40 AM
How to use URL to define response type - by El Forum - 02-10-2013, 02:45 AM
How to use URL to define response type - by El Forum - 02-20-2013, 04:00 AM
How to use URL to define response type - by El Forum - 02-20-2013, 05:46 AM
How to use URL to define response type - by El Forum - 02-20-2013, 02:07 PM
How to use URL to define response type - by El Forum - 02-20-2013, 10:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB