Simple way to auto load modules without complicate definition of routes

Overview

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!

You might also like...
Friendly open source CMS forged on Codeigniter 3. FI v1.x uses the old lite theme and all modules.
Friendly open source CMS forged on Codeigniter 3. FI v1.x uses the old lite theme and all modules.

ForgeIgniter v1.x - CI-3.x Friendly open source CMS forged on Codeigniter 3 This version is now discontinued, please check version 2 or 3 for updates.

Scorm Player Api for play scorm modules

flux-scorm-player-api Scorm Player Api for play scorm modules Installation Native Download RUN (mkdir -p /%path%/libs/flux-scorm-player-api && cd /%pa

MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way
MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way

Mysql Optimizer mysql optimizer also known as MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query

PPM is a process manager, supercharger and load balancer for modern PHP applications.
PPM is a process manager, supercharger and load balancer for modern PHP applications.

PPM - PHP Process Manager PHP-PM is a process manager, supercharger and load balancer for PHP applications. It's based on ReactPHP and works best with

The game is implemented as an example of scalable and high load architecture combined with modern software development practices
The game is implemented as an example of scalable and high load architecture combined with modern software development practices

Crossword game The game is implemented as an example of scalable and high load architecture combined with modern software development practices Exampl

Helper to automatically load various Kirby extensions in a plugin

Autoloader for Kirby Helper to automatically load various Kirby extensions in a plugin Commerical Usage This package is free but if you use it in a co

Load-Balance PaperCut ETP Print Queues using Postfix

ETP Load Balancing for PaperCut using Postfix This script is designed to allow you to load balance a single Email-To-Print address against multiple pr

Plugin for Kirby that allows you to load assets generated by Vite.

Kirby Vite Plugin Plugin for Kirby that allows you to load assets generated by Vite. In development mode, assets are loaded from Vite's development se

Automatically load the next page of products in Magento. Easy to install and configure, this module works 100% out of the box with vanilla Magento 1.9.x and earlier.

Automatically load the next page of products in Magento. Easy to install and configure, this module works 100% out of the box with vanilla Magento 1.9.x and earlier.

Comments
  • How to call model in controller?

    How to call model in controller?

    Hi,

    I have used you auto router module, done some changes as per my needs. Can you please help me in solving two current issues.

    1. I have used the module system, but how do i use multiple controller in this. What i have seen it seems that for every controller , every action i have to set in config.
    2. How to i call model in controller. For saving form and other things.

    It will be very help full if you can help me into this.

    Thanks

    opened by vinaysikarwar 9
  • Issue with the Core\Directory class

    Issue with the Core\Directory class

    The isWritable function of the Core\Directory class seems to always return false. This class uses 'return is_writable('/'.$path);'. This should be 'return is_writable($path);'

    opened by hdylanh 2
  • Can you help me in changing the module path directory

    Can you help me in changing the module path directory

    Hi,

    There is one request for you.

    Currently as per your module you have added the adminModule and frontendModule.

    I want the dir structure like app/modules/core/admin app/modules/core/frontend

    Thanks

    opened by vinaysikarwar 2
Owner
Kamil
Backend/Frontend developer with strong passion :)
Kamil
salah eddine bendyab 18 Aug 17, 2021
SlimJim was born out of a need for a simple auto update script which would update multiple development/test environments every time someone

SlimJim WHY? SlimJim was born out of a need for a simple auto update script which would update multiple development/test environments every time someo

Jesal Gadhia 100 Apr 22, 2022
This plugin can be embedded in PHP application to give the web application specific routes/href

Routes Plugin PHP This plugin can be embedded in PHP application to give the web application specific routes/href location and for entering specific/l

Ifechukwudeni Oweh 7 Jul 17, 2022
Test essentials for writing testable code that interacts with Magento core modules

Essentials for testing Magento 2 modules Using mocking frameworks for testing Magento 2 modules is counterproductive as you replicate line by line you

EcomDev B.V. 9 Oct 6, 2022
Library for check dependency between modules inside projects

PHP Dependency analyzer PHP DA is tool for check and support dependencies inside your project clear. For example: You have project with 3 root namespa

Kir Apukhtin 12 Nov 15, 2022
Experimenting with Zabbix frontend modules

Modules Request for new example can be left as issue for this repository, will do my best to implement if it is possible. Extending host popup menu Ac

null 1 Sep 19, 2022
WordPress plugin which contains a collection of modules to apply theme-agnostic front-end modifications

Soil A WordPress plugin which contains a collection of modules to apply theme-agnostic front-end modifications. Soil is a commercial plugin available

Roots 1k Dec 20, 2022
Magento-composer-installer - Composer installer for Magento modules

!!! support the maintainer of this project via Patreon: https://www.patreon.com/Flyingmana Magento Composer Installer The purpose of this project is t

null 213 Sep 24, 2022
This module adds a command to easily generate "modules" in Laravel and install them using composer.

Laravel Module Create This module adds a command to easily generate "modules" in Laravel and install them using composer Installation Simply install t

null 2 Feb 18, 2022
Check modules in app/code and vendor for PHP 8 compatibility status - PHP_CodeSniffer & php-compatibility standard

M2 PHP version compatibility check How To use Requires PHP 7.3+ | PHP 8 This app will run PHP_CodeSniffer with phpcompatibility/php-compatibility on t

William Tran 24 Oct 13, 2022