Giter Site home page Giter Site logo

phalcon-autorouter's Introduction

Phalcon-autorouter

Version 2.0

Example full application with various libraries included in this example

Change log

  • Structure have been changed and updated to more clear and better working
  • Added support to define full custom folder structure and set it in configuration file
  • Add various usable libraries and features as plugin Installer, Observer, Directory, File adapter, Image, Mail etc.
  • Observer support to define custom observer events on both sides, then execute events see example in plugin structure. Module observer listeners can be registered in module config file and events in installation script of plugin. See example config and plugin.
  • Added support for rest routing
  • Added support to define custom rest routing actions
  • Added support for Phalcon 1.0 in AutoRoute plugin and AccessControll
  • Fix matching url to route
  • Improve loading and performance of access controll
  • Version 1.0 it's not more supported, for older projects please use branch v1 to access old AutoRouting plugin
  • Sofdream namespace and folder have been removed in new version is Core

Dependencies

  • Phalcon 1.3.1 +
  • \Core, \Helper, \Plugin and all libraries included in library
  • Multi-Module Phalcon app

Installation

  • Copy contents of projects
  • Edit app/config/config.json and update db and path settings if neccessary

How it works ?

AutoRoutin plugin route application based on URL in order /module/controller/action/. When module, controller or action have not been found AutoRoute plugin automaticaly shift route for specific part and set it for next part eg.: /module/controller/action/ where module is not been found then automatic default module have been used and module part is set as an "controller". Same process happening until all parts are defined or found. Error action is being used when no default actions are set in configuration.

Example

Url: /manager/param/value/

Url will be routed to: manger module with indexAction rest of parameters behind /manager/ will be parsed and accessible in order /key/value/ in this case $this->request->getParam('param') will return value.

Url: /admin/my-own/param/value/

Url will be routed to: manger module to myOwnController and indexAction rest of parameters behind /manager/my-own/ will be parsed and accessible in order /key/value/ in this case $this->request->getParam('param') will return value.

Accessing params

From controller is possible to access params from request

//url /admin/mycontroller/param/value/
$param = $this->request->getParam("param");

The request will return value.

Accessing params with url map

In any reqeust it can be sat some map for url params.

//url: /admin/mycontroller/mycustomvalue/mynextvalue/
$this->request->setMap(new \Core\Http\Url\Map("/:mycustomname/:mynextname");
$myParam1 = $this->request->getParam("mycustomname");// returns mycustomvalue
$myParam2 = $this->request->getParam("mynextname");//returns mynextvalue

To access part's what have been shifted (/admin/mycontroller/) durring auto routing process we can use

$this->request->getParam("module"); // to access module name ( admin )
$this->request->getParam("controller"); //to access url controller value
$this->request->getParam("action"); //to access url action name 

ENJOY!

phalcon-autorouter's People

Watchers

QiPT avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.