PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] What is the best way to route to different controllers in CakePHP depending on HTTP header values?

 April 22, 2022     cakephp, cakephp-2.3, http-headers, routes     No comments   

Issue

I'm looking for a way to route URLs to different controllers depending on the value of the HTTP 'Accept' header.

All I have found so far is the official CakePHP documentation on routes but it is not very detailled.

Is this possible using route configurations or do I have to do this another way (e.g. by implementing a DispatcherFilter to inspect the CakeRequest)?


Solution

I want a set-up where I can seamlessly distribute responsibilities between server side and client side: e.g. letting the client handle the view creation instead of the server responding with an HTML document.

Guess you're using something like AngularJS? Well, then you expect a data format back instead of HTML I guess. So request application/json via the accept header and / or the extension. Cake can detect both and respond accordingly.

Read about JSON and XML views in the manual.

http://book.cakephp.org/2.0/en/views/json-and-xml-views.html



Answered By - floriank
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing