cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

DI router

Open renatogabrielbr opened this issue 11 years ago • 9 comments

The problem https://forum.phalconphp.com/discussion/7849/router-mount#C21343

di->set('router') has not autoloader class

https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/application.zep

Linha 210 let router = dependencyInjector->getShared("router");

Linha 280 moduleObject->registerAutoloaders(dependencyInjector);

renatogabrielbr avatar Jul 30 '15 01:07 renatogabrielbr

To submit a bug you need to provide a single PHP file with all the necessary code to reproduce the issue.

andresgutierrez avatar Jul 30 '15 01:07 andresgutierrez

/configs/services.php

$di->set('router', function () {

    $router = new Router();

    include __DIR__.'/../library/System/Routes/Loja.php';
    include __DIR__.'/../library/System/Routes/Admin.php';
    include __DIR__.'/../library/System/Routes/Frontend.php';
    $router->mount(new \System\Routes\Frontend);
    $router->mount(new \System\Routes\Loja);
    $router->mount(new \System\Routes\Admin);

    $router->notFound(array(
        "controller" => "index",
        "action" => "notfound"
    ));

    return $router;
});

renatogabrielbr avatar Jul 31 '15 11:07 renatogabrielbr

After running your test:

Notice: Undefined variable: di in /Users/phalcon/cphalcon/a.php on line 3
PHP Fatal error:  Call to a member function set() on null in /Users/phalcon/cphalcon/a.php on line 3

andresgutierrez avatar Jul 31 '15 15:07 andresgutierrez

This is a shortcode, and all another works here the full code All other di-set in the same file works problem is only in router.

index.php http://pastebin.com/2e35MpFJ

config.php ( same for all modules ) http://pastebin.com/qdxV3zcT

services.php http://pastebin.com/QRq6A5FZ

Module.php ( same for all modules ) http://pastebin.com/wD0gB3mv

renatogabrielbr avatar Aug 01 '15 07:08 renatogabrielbr

Looks to me that router are not able to call class, can you make a test in your router calling any class from library!

renatogabrielbr avatar Aug 01 '15 08:08 renatogabrielbr

services.php line 3 Phalcon\DI\FactoryDefault

should modified to Phalcon\DI\FactoryDefault as FactoryDefault

becase you create an instance by FactoryDefault, not Phalcon\DI\FactoryDefault in line 22

goqihoo avatar Aug 01 '15 08:08 goqihoo

Is the same, because as is just to set an alias. and in others di->set all works fine,

renatogabrielbr avatar Aug 01 '15 08:08 renatogabrielbr

$di->set dispatcher if you look i use 3 \System\ Class

renatogabrielbr avatar Aug 01 '15 09:08 renatogabrielbr

I'm closing this issue due to the lack of any reaction. I'll open it again if the need arises and providing a minimal script to reproduce.

sergeyklay avatar Sep 30 '16 10:09 sergeyklay