Welcome Guest, Not a member yet? Register   Sign In
Controller Method file extensions? (.xml or .php)
#11

[eluser]slowgary[/eluser]
The other argument is that key-value pairs don't require the user to remember which order to send the parameters.

Try echoing your $method and $content_type. I think CI replaces your periods with an underscore.
#12

[eluser]Fenix[/eluser]
Nope, it doesn't. The period is left as is. When I echo $content_type it gives me ".xml", assuming the method is "categories.xml", but if it is "categories.php" it won't even go to the controller because it thinks I am looking for an actual file named "categories.php".

I tried adding a custom route to routes.php like this:
$route['api/categories.php'] = 'api/categories';

It doesn't work but I didn't expect it to...

Any other ideas?
#13

[eluser]slowgary[/eluser]
Strange... it replaces mine, and I'm able to send filename.php just fine. Mine is the default controller, CI version 1.7.1, and I'm pretty sure my .htaccess is not doing it.
#14

[eluser]slowgary[/eluser]
I also have the url suffix set to ".html" in config.
#15

[eluser]Phil Sturgeon[/eluser]
You might be adding in a complication that you don't need. Most API's I have worked with simply use &format=json and run it all via the same file.

Anyway, what .htaccess are you using for this as it should not be looking for an actual categories.php. The fact the routing fails also suggests CI is not handling this request.
#16

[eluser]Fenix[/eluser]
Ahhh... I forgot about the .htaccess.

Here is my .htaccess file... I'd like to keep my php files safe. Is there a way I could allow it for any after /api/?

Code:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
    # mod_rewrite rules
    RewriteEngine on

    # If the file is NOT the index.php file
    RewriteCond %{REQUEST_FILENAME} !index.php

    # Hide all PHP files so none can be accessed by HTTP
    RewriteRule (.*)\.php$ index.php/$1                          // <------------ AHA! (i think)
    
    # If the file/dir is NOT real go to index
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>
#17

[eluser]xwero[/eluser]
[quote author="Fenix" date="1240602530"]I think you are contradicting yourself with this one. URLs are hierarchical. It is much easier for the user to see the key-value pairs in the query string. It also eliminates confusion when you get into required vs optional parameters. I also believe you lose site of the actual endpoint you are trying to access if you use your method.[/quote]
Urls don't have to be hierarchical, that is where the uri_to_assoc method comes in. Required segments are single segments, optional segments come in pairs.

My main point is your url building divides things that belong together. Personally i don't care about other apis. I want to give the users of my service the easiest api url possible. The format i suggested is the one i think is most logical.




Theme © iAndrew 2016 - Forum software by © MyBB