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.

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;
    }
}


30.7k
edited Aug '15

Hi,

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



64.3k
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;
    });


30.7k

Looks correct indeed.

Didn't you forget to declare:

use Phalcon\Mvc\View;

in your backend Module.php



64.3k
Accepted
answer

turned out to be .htaccess problem