Created
May 12, 2011 23:08
-
-
Save meddulla/969648 to your computer and use it in GitHub Desktop.
restfull output urls for code igniter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <IfModule mod_rewrite.c> | |
| RewriteEngine On | |
| #Checks to see if the user is attempting to access a valid file, | |
| #such as an image or css document, if this isn't true it sends the | |
| #request to index.php | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteCond %{REQUEST_FILENAME} !-d | |
| #This last condition enables access to the images and css folders, and the robots.txt file | |
| #Submitted by Michael Radlmaier (mradlmaier) | |
| RewriteCond $1 !^(index\.php|public|images|robots\.txt|css) | |
| RewriteRule ^(.*)$ index.php/$1 [L,QSA] | |
| </IfModule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $config['index_page'] = ''; | |
| $config['uri_protocol'] = 'AUTO'; | |
| $config['url_suffix'] = '';//required | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //eg welcome/index | |
| $route['([a-z]+)/([a-z]+)'] = "$1/$2"; | |
| //eg welcome/index.json | |
| $route['([a-z]+)/([a-z]+).([a-z]+)'] = "$1/$2"; | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
| class Welcome extends CI_Controller { | |
| public function index() | |
| { | |
| $this->load->helper('url'); | |
| echo 'URL: ' . current_url().'<br/>'; | |
| echo 'FORMAT: ' . $this->_format().'<br/>'; | |
| echo 'Building a url: ' . site_url("welcome/local/123.html").'<br/>'; | |
| echo 'INTERESTING OUTPUTS: .json, .xml, .html, .cache <br/>'; | |
| echo 'ACTIONS: .clear (->an action to clear cache)'; | |
| } | |
| //this should be moved to a helper function | |
| //or a MY_Controller should be created | |
| //but it shows how this can be done | |
| //could also be done in MY_Model (a la rails) | |
| //as long as cache control is also there | |
| private function _format() | |
| { | |
| $current_url = current_url(); | |
| $extension = substr(strrchr($current_url, '.'), 1); | |
| if (empty($extension)) { | |
| return 'html';//default extension | |
| } | |
| return $extension; | |
| } | |
| } | |
| /* End of file welcome.php */ | |
| /* Location: ./application/controllers/welcome.php */ |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
main logic in routes.php & welcome.php