I am stucked at one point in which I need to get JSON response if I pass .json behind the URL as below Example:
http://www.urlabc.com/home.json
The same way I need to get XML data like,
http://www.urlabc.com/home.xml
Please help me.
You can achieve it by using $_SERVER
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
This will return you actual path i.e http://www.urlabc.com/home.json
ANd by using pathinfo You get the extension of url as
echo $ext = pathinfo($actual_link, PATHINFO_EXTENSION);
if($ext=="json")
{
// json code
}
if($ext=="xml")
{
// xml code
}
I think you should use pass "json" as query parameter
e.g.[http://www.example.com?type=json]
Also use Codeigniter Rest Server Click here