Extend core libraries to detect the request file type and load applicable view |
[eluser]Unknown[/eluser]
I extend core libraries to detect the request file type and load applicable view. What I want to do is that if user request 'http://localhost/ci/blogs/index.xml', it will try to load a view for XML. In other cases: If request 'blogs/index', load 'views/index.php' to render HTML document (default type). If request 'blogs/index.xml', load 'views/index.xml.php' to render XML document. If request 'blogs/index.pdf', load 'views/index.pdf.php' to render PDF document. and so on. Code: class MY_URI extends CI_URI { Code: class MY_Loader extends CI_Loader {
[eluser]wiredesignz[/eluser]
I dislike core hacks for such a trivial thing. The same thing can be acheived using routes and the _remap() function, I have tested and _remap() gets passed the page.ext value from the url. its then easy to determine the extension and do your stuff. ![]()
[eluser]Spockz[/eluser]
Could you eleborate that? I want to use a very similar functionality. Instead of using *.extension.php I want to use extension/*.php. How would you accomplish this?
[eluser]xwero[/eluser]
Why not use /blogs, /blogs/xml, /blogs/pdf if the only task is to serve a different file type. In your controller you do Code: // fetch data
[eluser]louis w[/eluser]
I have been thinking of doing something like this. I think I am going to use the routes to change output format http://localhost/blogs/view/1234 or http://localhost/_html/blogs/view/1234 >> output normally/html http://localhost/_xml/blogs/view/1234 >> output as xml http://localhost/_pdf/blogs/view/1234 >> output as pdf http://localhost/_json/blogs/view/1234 >> output as json It's only an idea at this point, not fully realized.
[eluser]xwero[/eluser]
Why make it hard when it can be easy? shirock wants urls like blogs/index, blogs/index.xml, blogs/index.pdf. CI makes it possible not to use the default function which means less typing for the users. Louis w the extension is located at the end so why do you want to add it as a prefix? Coding standards state make everything as readable and as short as possible this is also the case when you set up a url schema.
[eluser]louis w[/eluser]
How would you switch the output on the extension? _remap?
[eluser]louis w[/eluser]
You are contradicting yourself - #3 says to test against uri segment, but you say this in post #5 Quote:shirock wants urls like blogs/index, blogs/index.xml, blogs/index.pdf. CI makes it possible not to use the default function which means less typing for the users.
[eluser]xwero[/eluser]
By that sentence i mean you can remove index from the url. You only need to add the extension if you want another output than the default output. |
Welcome Guest, Not a member yet? Register Sign In |