6
votes

Can you give me some information on how to create a new Symfony2 project?

I started to get the symfony/symfony-sandbox from github as a tar-ball. Then I removed its old src/vendor content.

I get latest vendor libs with git submodule. ( fabpot/Symfony, doctrine, migrations, ...).

The problem is the sandbox seems out of date compared to latest fabpot/Symfony code.

So I started to modify what changed ( FoundationBundle rename, some method signature changes (like registerContainerConfiguration, ... ).

I still get this error:

Symfony\Components\HttpKernel\Exception\NotFoundHttpException: Unable to find the controller.

It seems to be a problem with routing: the request matches no controller.

Do you have any idea?

Even better, does anybody has a sandbox which works with latest Symfony code?

1
After even more research, It seems that the "core.load_controller" event is never processed. Or it should be handled by a ControllerLoaderListener.Florian Klein
Do you really think the sandbox is supposed to be up-to-date? After reading this page : symfony-reloaded.org/code , I don't. It says the sandbox is updated "on a regular basis" (last update seems to be on 30/06/2010), and that if you want to get "bleeding edge" software, you should install symfony2 from here : github.com/symfony/symfony Doesn't following the quick-tour guide help? It can be found here : symfony-reloaded.org/quick-tour/part-1greg0ire
Yes, i've already read the entire symfony/learn docs and the quick tour (and constantly using it). The only reason why i started from sandbox is for it's skeleton. I'll retry with bleeding edge Symfony. Thanks.Florian Klein
Is there any default kernel i could start with ? (And works with latest symfony)Florian Klein

1 Answers

3
votes

The main problem is that Symfony changes too fast to maintain a working solution based on the trunk/main branch.

Maybe I had not the best approach on how to start, but after some searchs, I came to a solution:

I finally found my problem:

all my problems were DI related.

The first problem was that the ControllerLoaderListener wasn't observing the "core.load_controller" event.

It was because I had deactivated the web extension in my config.yml ( shame on me... but I was testing!)

After that, I had another problem with the "router" service. It wasn't loaded neither!

By looking here:

src/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/yml/config/config.yml

I found that the router service is activated by this config.yml:

parameters:
    kernel.include_core_classes: false

kernel.config: ~

web.config: #enables the Web DI extension
  router: { resource: "%kernel.root_dir%/config/routing.yml" } #enables the Routing DI extension

web.templating: ~

doctrine.dbal: ~
doctrine.orm: ~

If I say this to you all, It's just because I hope to economize some headaches to other people :)

And if someone's interested, here is a working Kernel who works with latest fabpot/Symfony repo.

<?php

require_once __DIR__.'/../src/autoload.php';

use Symfony\Framework\Kernel;
use Symfony\Components\Routing\Loader\YamlFileLoader as RoutingLoader;

use Symfony\Components\DependencyInjection\Loader\LoaderInterface;

class ECommerceKernel extends Kernel
{
    public function registerRootDir()
    {
        return __DIR__;
    }

    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Framework\KernelBundle,
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle,
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle,
            new Symfony\Bundle\DoctrineBundle\DoctrineBundle,
            new Symfony\Bundle\DoctrineMigrationsBundle\DoctrineMigrationsBundle,
            new Application\ECommerceBundle\ECommerceBundle,
        );

        if ($this->isDebug()) {
        }

        return $bundles;
    }

    public function registerBundleDirs()
    {
        $bundles = array(
            'Application'        => __DIR__.'/../src/Application',
            'Bundle'             => __DIR__.'/../src/Bundle',
            'Symfony\\Framework' => __DIR__.'/../src/vendor/symfony/src/Symfony/Framework',
            'Symfony\\Bundle'    => __DIR__.'/../src/vendor/symfony/src/Symfony/Bundle',
        );

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        return $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }

    public function registerRoutes()
    {
        $loader = new RoutingLoader($this->getBundleDirs());

        return $loader->load(__DIR__.'/config/routing.yml');
    }
}