Download the PHP package atk14/sluggish-router without Composer
On this page you can find all versions of the php package atk14/sluggish-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package sluggish-router
SluggishRouter
Base class for ATK14 routers generating nice looking URLs with slugs
It can handle "detail" URLs for models that have method and static method . You can find both in the Atk14Catalog.
Basic usage
Router class:
<?php
// file: config/routers/articles_router.php
class ArticlesRouter extends SluggishRouter {
var $patterns = [
"en" => ["index" => "/articles/", "detail" => "/articles/<slug>/"],
"cs" => ["index" => "/clanky/", "detail" => "/clanky/<slug>/"],
"sk" => ["index" => "/sk/clanky/", "detail" => "/sk/clanky/<slug>/"],
];
// var $model_class_name = "Article"; // by default determined automatically according to the router's class name
// var $target_controller_name = "articles"; // by default determined automatically according to the router's class name
}
Loading router:
<?php
// file: config/routers/load.php
Atk14Url::AddRouter("ArticlesRouter"); // the default namespace ("")
Atk14Url::AddRouter("blog","ArticlesRouter"); // loading ArticlesRouter also into namespace blog
In a template:
{a controller="articles" action="detail" id=123}Here is the article{/a}<br>
{a controller="articles" action="index"}Show all articles{/a}
Rendered HTML:
<a href="/articles/why-is-the-atk14-so-cool/">Here is the article</a><br>
<a href="/articles/">Show all articles</a>
An easier way to set the routes:
<?php
// file: config/routers/articles_router.php
class ArticlesRouter extends SluggishRouter {
var $patterns = [
"en" => "articles", // same as ["index" => "/articles/", "detail" => "/articles/<slug>/"]
"cs" => "clanky", // same as ["index" => "/clanky/", "detail" => "/clanky/<slug>/"]
"sk" => "sk/clanky", // same as ["index" => "/sk/clanky/", "detail" => "/sk/clanky/<slug>/"]
];
}
Setting only detail routes:
<?php
// file: config/routers/articles_router.php
class ArticlesRouter extends SluggishRouter {
var $patterns = [
"en" => "/articles/<slug>/", // same as ["detail" => "/articles/<slug>/"]
"cs" => "/clanky/<slug>/", // same as ["detail" => "/clanky/<slug>/"]
"sk" => "/sk/clanky/<slug>/", // same as ["detail" => "/sk/clanky/<slug>/"]
];
}
Fallback route
A fallback route for all the unlisted languages can be specified using the asterisk symbol.
<?php
// file: config/routers/articles_router.php
class ArticlesRouter extends SluggishRouter {
var $patterns = [
"*" => ["index" => "/<lang>/articles/", "detail" => "/<lang>/articles/<slug>/"],
];
}
Installation
Use the Composer to install SluggishRouter.
cd path/to/your/project/
composer require atk14/sluggish-router
Testing
composer update --dev
cd test
../vendor/bin/run_unit_tests
Licence
SluggishRouter is free software distributed under the terms of the MIT license
All versions of sluggish-router with dependencies
PHP Build Version
Package Version
Requires
php Version
>=5.3.0
The package atk14/sluggish-router contains the following files
Loading the files please wait ....