Virtual file extensions hook for CodeIgniter |
[eluser]Unknown[/eluser]
Hi CodeIgniters programmers here I wanna make my own routing procedure for improving the Ajax programing arquitecture. Like I didn't care to reinvent the wheel, I looked for something of this kind and found Another AJAX approach from CI in the CodeIgniter Wiki; and I think this was very good for starting; but I needed more to specify several formats althought this archives wouldn't exists but simulated by a PHP, for having variables outputs (Ajax could be Xml o Json for example), so I decided to do my own mapping routine. So you have to change the original Router.php for the new one..., like this... Original: \system\libraries\Router.php Code: $this->uri->_fetch_uri_string(); Newone: \system\libraries\Router.php Code: $this->uri->_fetch_uri_string(); // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. Code: if ($this->uri->uri_string == '') http://localhost/ajaxapp/module/file.json The routing will clean this URL to: http://localhost/ajaxapp/module/file And will put the $CI->router->format to the specific format. The formats I care in this example: json js xml So we could decide to show the wanted output like for example return a json outoput or a table made in html, like this: Code: //Controller function example This is a example of a functionality that’s could be request by ajax or by a normal request(html). Not all functions could need this issue, only use it when you have different ways to output this; for example some function will have the case 'xml': instruction for "based xml Ajax call" or for a regular RSS and the arguments defines the rest. Thanks to anybody who reads this article, I hope it would be useful for you. I will thanks feedback to me. Greetings, Eliecer (EliuX) Hdz. Garbey |
Welcome Guest, Not a member yet? Register Sign In |