Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Router Annotations in Micro

router.php

use Phalcon\Mvc\Router\Annotations as RouterAnnotations;

$routerA = new RouterAnnotations(false);
$routerA->addResource('Conf', '/conf');
$app->setService('router', $routerA, true);

ConfController.php

/**
 * @RoutePrefix('/conf')
 */
class ConfController extends Phalcon\Mvc\Controller
{
    /**
     * @Get('/')
     */
    public function indexAction()
    {
        //$this->assets->addJs('js/jquery.js');
        echo ('ConfController');
        d($this->view);
        $this->view->render(get_class(), 'indexAction', array());
    }

}

index.php

  // Initializing application
  $app = new \Phalcon\Mvc\Micro();

  // Setting DI container
  $app->setDI($di);

    // Processing request 
  $app->handle();

And i am getting "Matched route doesn't have an associated handler"

if I dump $app after handle() i see all members begining with _ are empty

_handles must not be empty https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/micro.zep

            let matchedRoute = router->getMatchedRoute();
            if typeof matchedRoute == "object" {

                if !fetch handler, this->_handlers[matchedRoute->getRouteId()] {
                    throw new Exception("Matched route doesn't have an associated handler");
                }

What is wrong? How to populate _handle? Annotations are usable in Micro or in Full/MVC only



57.1k
Accepted
answer

I don't think micro supports annotations.

This repo should implement it: https://github.com/OakBehringer/phalcon-micro-route-annotations

I don't think micro supports annotations.

This repo should implement it: https://github.com/OakBehringer/phalcon-micro-route-annotations

Thank you, I also came to idea than Router/Annotations are not complete for Micro (it inherits Phalcon/Router which works good if setting manual paths). I saw this repo too, but i doubt about speed/caching ... if it reads all the controllers files each time app gets request it would be a problem. For now i move forward with manual writing routes to Phalcon/Router.

edited Dec '17

Yea it uses memory annotations adapter. You could use it to create other adapter based reader like redis or memcached.

Yea it uses memory annotations adapter. You could use it to create other adapter based reader like redis or memcached. Cool, thanks for info, Wojciech. Will examine it in details later - too much question/experiments ahead.