Vesthelm Engine

2.1.1 User Guide

URI Class

The URI Class provides functions that help you retrieve information from URI strings.

Calling the URI Class

$URI = $this->URI;

Getting First URI Part

//Example URL: http://www.example.com/index.php/bulletin-board/add-bulletin/

$first_part = $this->URI->getFirstPart();

echo $first_part; //Outputs: bulletin-board

Getting Last URI Part

//Example URL: http://www.example.com/index.php/bulletin-board/add-bulletin/

$last_part = $this->URI->getLastPart();

echo $last_part; //Outputs: add-bulletin

Getting Specific URI Part

Parts are numbered from left to right. For example, if full URL is:

http://www.example.com/index.php/bulletin-board/add-bulletin/

The parts numbers would be:

0. bulletin-board
1. add-bulletin

To get string "bulletin-board" from example URL:

$string = $this->URI->getPart(0);

echo $string; //Outputs: bulletin-board

Getting the Total Number of URI Parts

//Example URL: http://www.example.com/index.php/bulletin-board/add-bulletin/

$total_parts = $this->URI->getTotalParts();

echo $total_parts; //Outputs: 2

Getting URI String

For example, if your full URL is:

http://www.example.com/index.php/bulletin-board/add-bulletin/
$uri_string = $this->URI->getURI();

echo $uri_string;

Outputs:

bulletin-board/add-bulletin

Turning URI Parts into an Associative Array

URI:

index.php/bulletin-board/add-bulletin/title/test/description/asd/
$array = $this->URI->URIToAssoc();

echo $array['title']; //Outputs: test
echo $array['description']; //Outputs: asd

Variable $array:

array(
    'bulletin-board' => 'add-bulletin',
    'title' => 'test',
    'description' => 'asd'
);

The first argument of the function lets you set an offset:

$array = $this->URI->URIToAssoc(3);

echo $array['title']; //Outputs: test

Variable $array:

array(
    'title' => 'test',
    'description' => 'asd'
);

Turning an Associative Array into URI Parts

$array = array(
    'bulletin-board' => 'add-bulletin',
    'title' => 'test',
    'description' => 'asd'
);

$uri_string = $this->URI->assocToURI($array);

echo $uri_string; //Outputs: bulletin-board/add-bulletin/title/test/description/asd/