Classes and Methods Using e107's built-in classes and methods.

Urls

You can generate a search-engine-friendly URL (where supported) using the following method:

e107::url(plugin, key, row, options);
Value Type Description
plugin string Folder name of the plugin. (will use data from e_url.php)
key string Unique key
row array array of variable data such as id, title etc. eg. user_id, user_name
options array An associative array of additional options, with the following elements:
'mode': abs | full
'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.
'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.

Example

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

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

$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:

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

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


Thursday 13 June 2013 - 00:00:00 Cameron,