hoaproject / Router

The Hoa\Router library.
https://hoa-project.net/
28 stars 11 forks source link

Routing not completed #38

Closed Ecureuilvirtuel closed 8 years ago

Ecureuilvirtuel commented 8 years ago

Environnement : windows 7 PHP 5.4.34

Problem : My route is not dispatche correctly, so i speak with hywan and we try to isolate the problem with hoa/router.

So the code is :

$router = new Hoa\Router\Http(); $router->get('/supervisor', 'supervisor', 'index'); $router->route('/supervisor');

print_r( $router->getTheRule() );

The expected response :

Array ( [0] => 0 [1] => /supervisor [2] => Array ( [0] => get )

[3] => supervisor
[4] => index
[5] => 
[6] => Array
    (
        [_uri] => supervisor
        [_method] => get
        [_domain] => 
        [_subdomain] => 
        [_call] => index
        [_able] => 
        [_request] => Array
            (
            )

    )

)

And my response is :

Array ( [0] => 0 [1] => supervisor [2] => Array ( [0] => get )

[3] => /supervisor
[4] => supervisor
[5] => index
[6] => Array
    (
        [_uri] => supervisor
        [_method] => get
        [_domain] => bddobs.dev
        [_subdomain] => 
        [_call] => supervisor
        [_able] => index
        [_request] => Array
            (
            )

    )

)

Jir4 commented 8 years ago

For me id is missing in your syntax :

<?php
$router->get('/supervisor', 'supervisor', 'index');

You use the get() magic method with three arguments : pattern, calland able.

But in https://github.com/hoaproject/Router/blob/master/Generic.php#L163 and https://github.com/hoaproject/Router/blob/master/Generic.php#L108-L125 we can see that the correct syntax must be something like :

get(<id>,<pattern>,<call>,<able>)

So i think you have to try something like :

<?php
$router->get('SuperVisorIndex','/supervisor','supervisor','Index')

I can't try for now but i hope it's the good answer.

Ecureuilvirtuel commented 8 years ago

It does't change anything.

"hoa/router" : "2.15.02.26", "hoa/dispatcher" : "0.15.05.29",

<?php $router = new Hoa\Router\Http(); $router->get('SuperVisorIndex', '/supervisor', 'supervisor', 'index'); $router->route('/supervisor');

echo print_r($router->getTheRule());

Jir4 commented 8 years ago

Uhm ok, i'll make a try with your versions of router and dispatcher

Jir4 commented 8 years ago

What did you want to do exactly ? if i understood correctly you want to call the Index method of your supervisor class when the http://domain/supervisor uri is called. That's it ?

Ecureuilvirtuel commented 8 years ago

It's that. I have un directory Application. Inside A directory Controller and Public. In the file Public/index.php i specify a route which redirect me to the Action index of the class Controller/SupervisorController with the url http://domain/supervisor.

Jir4 commented 8 years ago

Ok so you need some configuration on your dispatcher to tell it what it have to match :

try with this :

$dispatcher = new Dispatcher\ClassMethod([
    'synchronous.call'  => 'Application\Controller\(:call:U:)'
]);
Jir4 commented 8 years ago

Does it works ? @Ecureuilvirtuel

Ecureuilvirtuel commented 8 years ago

I have this configuration file for the dispatcher :

return array ( 'keywords' => array ( 'controller' => 'main', 'action' => 'main', 'method' => NULL, ), 'parameters' => array ( 'synchronous.call' => 'Application\Controller(:controller:U:)Controller', 'synchronous.able' => '(:action:U:)Action', 'asynchronous.call' => '(:%synchronous.controller:)', 'asynchronous.able' => '(:%synchronous.action:)Async', ), );

This configuration is good but the problem is still present.

Jir4 commented 8 years ago

There is a type in your configuration, a \ is missing before (:controller:U)

Ecureuilvirtuel commented 8 years ago

It is github which remove the "\".

Jir4 commented 8 years ago

:( each time i think i have found the answer ^^

Here my test : ecureuil

For me everything is ok !

Ecureuilvirtuel commented 8 years ago

Good job, problem solved :

my config was wrong :

'synchronous.call' => 'Application\Controller\(:controller:U:)Controller',
'synchronous.able' => '(:action:U:)Action',

and the solution is :

'synchronous.call' => 'Application\Controller\(:call:U:)Controller',
'synchronous.able' => '(:able:U:)Action',

Thank's a lot :+1:

Hywan commented 8 years ago

@Ecureuilvirtuel Can you close the issue please? @Jir4 Good job!

Jir4 commented 8 years ago

:bowtie: :sweat_smile:

Ecureuilvirtuel commented 8 years ago

@Hywan I can't close the issue, I have no right ...