Results 1 to 1 of 1
Hybrid View
-
29th Jun 2010, 10:21 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.com[php] Simulating file system URI's
In your htaccess use like:
Code:<IfModule mod_rewrite.c> RewriteEngine On #Rewrite the URI if there is no file or folder RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule>
PHP Code:class URI
{
var $uri;
var $segments = array();
function __construct()
{
$this->uri = $_SERVER['REQUEST_URI'];
$this->segments = explode('/',$this->uri);
}
function getSegment($id,$default = false)
{
$id = (int)($id - 1); //if you type 1 then it needs to be 0 as arrays are zerobased
return isset($this->segments[$id]) ? $this->segments[$id] : $default;
}
}
Code:http://mysite.com/posts/22/litewarez-shows-mvc-style-uri-access
PHP Code:$Uri = new URI();
echo $Uri->getSegment(1); //Would return 'posts'
echo $Uri->getSegment(2); //Would return '22';
echo $Uri->getSegment(3); //Would return 'litewarez-shows-mvc-style-uri-access'
echo $Uri->getSegment(4); //Would return a boolean of false
echo $Uri->getSegment(5,'fallback if not set'); //Would return 'fallback if not set'
Example of usuage in daily use
PHP Code:switch($Uri->getSegment(1))
{
case 'home':
case 'index':
default:
echo 'I am Index';
break;
case 'post':
if($Url->getSegment(2) != false) //We have id
{
echo sprintf('Showing post with id of %d',$Uri->getSegment(2));
}else
{
echo 'Bad URI, Expecting id but got nothing.';
}
break;
}
litewarez Reviewed by litewarez on . [php] Simulating file system URI's In your htaccess use like: <IfModule mod_rewrite.c> RewriteEngine On #Rewrite the URI if there is no file or folder RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 </IfModule> Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
LiveFile.org - new file sharing system now open for beta-testers!
By LiveFile.org Support in forum File Hosts Official SupportReplies: 30Last Post: 17th Sep 2012, 08:47 AM -
What is the Oldest File Hosting Site with Aff system ??
By myincome2020 in forum File Host DiscussionReplies: 23Last Post: 22nd Jul 2011, 11:13 AM -
File System Corrupt
By David. in forum Webmaster DiscussionReplies: 8Last Post: 9th Mar 2011, 10:18 PM -
[Selling] Web 2.0 - 100% Custom Coded - Unique File Sharing System
By jiexi in forum Completed TransactionsReplies: 7Last Post: 16th May 2010, 07:08 PM -
Linux File System Explained For Beginners
By Plutost in forum Tutorials and GuidesReplies: 4Last Post: 7th Sep 2009, 04:07 PM
themaLeecher - leech and manage...
Version 5.03 released. Open older version (or...