Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Latest commit

 

History

History
57 lines (42 loc) · 1.28 KB

Routing.md

File metadata and controls

57 lines (42 loc) · 1.28 KB

Routing

PHP Routing

namespace my_company;

use atsilex\module\Module;
use Silex\Application;
use Silex\ControllerCollection;

class MyModule extends Module {
    protected $machineName = 'my_module';
    protected $name        = 'My Module';
    protected $description = 'Study the how to write module.';
    
    public function connect(Application $app) {
        $route = $app['controllers_factory']; /** @var ControllerCollection $route */
        
        // @system.ctrl.home:actionGet-> my_company\controllers\HomeController::actionGet
        $route->get('/hello', '@system.ctrl.home:actionGet')->bind('hello');
        
        $route->get('/hi', function() {
            return 'Hi there!';
        })->bind('hello');
        
        return $route;
    } 
}

Yaml routing

First you needs to tell that you use YAML file to define routes:

namespace my_company;

use atsilex\module\Module;
use Silex\Application;
use Silex\ControllerCollection;

class MyModule extends Module {
    protected $machineName = 'my_module';
    protected $routeFile   = true;
}

Then define you routes, default location is your module's resources/config/routing.yml:

hello-yaml:
  path: /hello-yaml
  methods: [GET]
  defaults: { _controller: @foo.ctrl.hello:actionGet }