2017 © Pedro Peláez
 

library kohana-aliases

This module allows you to make usefull and beautifull URLs for your service.

image

codex-team/kohana-aliases

This module allows you to make usefull and beautifull URLs for your service.

  • Tuesday, April 17, 2018
  • by codex-team
  • Repository
  • 4 Watchers
  • 3 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Aliases module for Kohana Framework

This module allows you to make useful and beautiful URLs for your service., (*1)

You don't need more /user/<id> or /article/<id> cursors in routes. Now you can use simply /donald and /victory or /pokemon-go like addresses for different resources., (*2)

User Guide

Article describing this HMVC feature placed on our website https://ifmo.su/alias-system., (*3)

Installing

Firstly you need to copy this module to your project. You can download this repository and place its files to the /modules directory or attach it as a submodule., (*4)

git submodule add https://github.com/codex-team/kohana-aliases modules/aliases

To enable module push it to Kohana::modules() array in bootstrap.php, (*5)

Kohana::modules(array(
    'aliases' => MODPATH . 'aliases', // Aliases for URLs
    ...
));

Defining project's entities

In classes directory create a subdirectory Aliases with file Controller.php. You can copy classes/Kohana/Aliases/Controller.php., (*6)

Create constants for your site's entities and add them to Controllers map., (*7)

const ARTICLE   = 1;
const USER      = 2;
...

const MAP = array(
    self::ARTICLE   => 'Articles',
    self::USER      => 'Users',
    ...
);

It means that entity ARTICLE will be handled by controller with name Articles., (*8)

Subcontrollers

Aliases module suggest you two types of subcontrollers:, (*9)

  • Index for showing entities
  • Modify for do anything else with them
Example

If you have entity User, then create two controllers, (*10)

  1. To show user by uri /alice or /bob:

Controller/Users/Index.php with action action_show, (*11)

  1. To do any editions as adding, deleting. Uri: /my-great-article/edit or /not-a-good-user/ban

Controller/Users/Modify.php with all other actions e.g. action_edit, action_ban, action_delete., (*12)

All you need after is to include aliases creation and updating methods into your logic., (*13)

Set system routes

If you want to set up system routes for your site or block some which shouldn't be allowed to use as alias. Then use config/system-aliases.php file. Lock any count of system URIs by adding them to the array., (*14)

Database

Migrations for Aliases table in MySQL database migrations are in the migrations/Aliases.sql file., (*15)

Create a new alias

$alias         = Model_Aliases::generateUri($uri);
$resource_type = Aliases_Controller::ARTICLE;       // your own resource's type such as user, article, category and other
$resource_id   = 12345;

$article->uri = Model_Aliases::addAlias($alias, $resource_type, $resource_id);

Update alias

$resource_id   = $article->id;
$old_uri       = $article->uri;
$new_uri       = Model_Aliases::generateUri($uri);
$resource_type = Aliases_Controller::ARTICLE;

$article->uri = Model_Aliases::updateAlias($old_uri, $new_uri, $resource_type, $resource_id);

Remove alias

$hash = Model_Aliases::createRawHash($route);

Model_Aliases::deleteAlias($hash);

Database and cache

You can create a Model_DB_Aliases class and create your own function to work with database e.g. for use caching system., (*16)

Copy file classes/Model/DB/Aliases.php and rewrite functions., (*17)

Repository

https://github.com/codex-team/kohana-aliases/, (*18)

About CodeX

We are small team of Web-developing fans consisting of IFMO students and graduates located in St. Petersburg, Russia. Feel free to give us a feedback on team@ifmo.su, (*19)

The Versions

17/04 2018

dev-master

9999999-dev

This module allows you to make usefull and beautifull URLs for your service.

  Sources   Download

MIT

17/04 2018

dev-update

dev-update

This module allows you to make usefull and beautifull URLs for your service.

  Sources   Download

MIT