# URLs

{% hint style="danger" %}
**Please note:** This page is under construction and has not been finished yet.
{% endhint %}

## Introduction

You can generate a Search Engine Friendly (SEF) URLs using the following method:

```php
e107::url($plugin, $key, $row, $options);
```

<table><thead><tr><th>Parameter</th><th width="150">Type</th><th>Description</th><th>Mandatory?</th></tr></thead><tbody><tr><td>plugin</td><td>string</td><td>Folder name of the plugin. (will use data from <a href="../../plugin-development/extending-core-functionality-addons#e_url-php">e_url.php</a>)</td><td><strong>Yes</strong></td></tr><tr><td>key</td><td>string</td><td>Unique key</td><td><strong>Yes</strong></td></tr><tr><td>row</td><td>array</td><td>Array of variable data such as id, title etc. eg. user_id, user_name</td><td>No</td></tr><tr><td>options</td><td>array</td><td><p>An associative array of additional options, with the following elements:</p><ul><li><strong>mode</strong>: abs | full (returning the absolute path or full URL)</li><li><strong>query</strong>: an array of query key/value-pairs (without any URL-encoding) to append to the URL.</li><li><strong>fragment</strong>: a fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.</li></ul><p><em>(optional)</em></p></td><td>No</td></tr></tbody></table>

## **Examples**

### **Example 1: Forum topic URLs**

In this example we will generate search-engine-friendly URLs for a forum topic with the following code: .

```php
// these values are usually loaded from the database. 
$data = array(
	'forum_sef'		=>	'my-sef-forum-name', 
	'thread_id'		=>  2, 
	'thread_sef'	=>	'my-forum-topic'
); 

$url = e107::url('forum','topic', $data);
```

The code above loads the following file: `e107_plugins/forum/e_url.php` and generates a URL from the following array data with the unique key `topic`:

```php
$config['topic'] = array(
	'regex'    => '^forum/(.*)/(d*)-([w-]*)/???(.*)',
	'sef'      => 'forum/{forum_sef}/{thread_id}-{thread_sef}/',
	'redirect' => '/e107_plugins/forum/forum_viewtopic.php?id=$2'
 );
```

Only the value of 'sef' is used in this array. it substitutes the values `{forum_sef},` `{thread_id}` and `{thread_sef}` with the variables in the `$data` array.

The end result would look something like this: <http://sitename.com/forum/my-sef-forum-name/2-my-forum-topic>

### Example 2: Using optional parameters

{% hint style="info" %}
**TODO: Add examples using the options parameter**
{% endhint %}
