We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Routing problem

I cant get multi - module application to work

so when i open the page '/' its ok -> i see what i have to see.

If change my url to /admin

I have diffrent view there and stuff isntead i got this error

Service 'view' wasn't found in the dependency injection container

  $router->add(
  "/admin",
    array(
      'namespace'  => 'backend',
      'module'     => 'backend',
      'controller' => 'Admin',
      'action'     => 'index'
    )
  );

  $router->add('/', array(
    'module' => 'frontend',
    'controller' => 'index',
    'action' => 'index'
  ));

  $router->removeExtraSlashes(true);

in my backend index controller i got

<?php

namespace Modules\Backend\Controllers;

class AdminController extends ControllerBase
{

    public function indexAction()
    {
        echo "<pre>";
        print_r('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
        echo "</pre>";
        exit;
    }
}


43.9k
edited Aug '15

Hi,

error message has nothing to do with routing but you should check how you declare view service in your modules ...



85.5k
edited Aug '15

frontend and baclend/module.php file

public function registerServices(DiInterface $di)
{

    /**
     * Read configuration
     */
    $config = include __DIR__ . "/config/config.php";

    $di['dispatcher'] = function() {
        $dispatcher = new Dispatcher();
        $dispatcher->setDefaultNamespace("Modules\Backend\Controllers");
        return $dispatcher;
    };

    /**
     * Setting up the view component
     */
    $di->set('view', function () {
        $view = new View();

        $view->setViewsDir(__DIR__ . '/views/');
        $view->setLayoutsDir('../../common/layouts/');
        $view->setTemplateAfter('main');

        return $view;
    });


43.9k

Looks correct indeed.

Didn't you forget to declare:

use Phalcon\Mvc\View;

in your backend Module.php



85.5k
Accepted
answer

turned out to be .htaccess problem