1

In CodeIgniter I am using HMVC extension and I can have this structure for my modules:

modules/
         admin_auth
         admin_core
         admin_menu
         admin_templates
         flashnews
         flashnews_latest
         footer
         gallery
         pages/
               controllers/
                       admin.php
                       pages.php
               models/
                       mdl_pages.php
               views/
                       admin/
                              page_add.php
                              page_list.php
                       pages_front_list.php
         posts
         posts_latest
         templates
         videos

Which allow my to include admin parts into my modules and call it to admin_core and admin_menu modules.

Here it is explained in much more deatils (the last method) :

http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter

Could something like that be done in Symfony2 and if yes where I can find some tutorial how to acheve similar structure, so the modules have included admin part (controllers and views). I was searching but I didn't find anything like that.

Is there any book that talks about that in a detial, how to create admin with modules that contain amdin parts too?

twenkistat
  • 15
  • 2
  • Creating a bundle would do. Maybe you can start [from scratch](http://symfony.com/doc/current/book/page_creation.html#page-creation-bundles) or read about [what is a bundle](http://stackoverflow.com/q/5770753/1607098) – Touki Aug 13 '13 at 08:03
  • @Touki On the link you provided there is nothing about admin panel. Have your read Phil Sturgeon article to get a better idea what I want to do? – twenkistat Aug 13 '13 at 08:05
  • Just wrap your admin services, views, controllers or any functionality into an `AdminBundle` of your own. Or you can use a ready-to-use bundle like [SonataAdminBundle](https://github.com/sonata-project/SonataAdminBundle) – Touki Aug 13 '13 at 08:18
  • @Touki It's not a solution I guess. I want all my admin stuff that belongs to the module have in this module and not in another module. Maybe I am just not understanding your approach. Could you give me some example tutorial where they are creating a bundle with admin features and everything is inside the same budle e.g. PagesBundle? – twenkistat Aug 13 '13 at 08:28

1 Answers1

0

I think you misunderstood what Symfony2 offers you. I'll try to explain some of them for your use case.

What I understood

You want to create an admin panel on your website. It's a common case.

What to do

You should create a bundle for this whole content. Like AdminBundle

Step by step

Let's look at a Symfony2 directory structure. Here's an excerpt.

project/
    app/
        config/
            config.yml
            parameters.yml
        cache/
        AppKernel.php
    src/
        Acme/
            DemoBundle/
                Controller/
                Resources/
                    config/
                    public/
                    views/
                AcmeDemoBundle.php
    vendor/
        symfony/
        autoload.php
    web/
        .htaccess
        app.php
        app_dev.php

The whole project directory is your Application
It can contain a lot of different websites if needed or it can just be a single one.

Your application logic (website in this case) should be in the src folder, delegated as Bundle's
You can read more about what is a bundle or should everything be a bundle

Front End Logic

So, in your case you may have a FrontBundle which contains the frontend logic, like this

project/
    src/
        Acme/
            FrontBundle/
                Controller/
                    IndexController.php
                Resources/
                    views/
                        Index/
                            pages.html.twig
                        layout.html.twig

Acme\FrontBundle\Controller\IndexController

<?php

namespace Acme\FrontBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class IndexController extends Controller
{
    /**
     * @Route("/pages")
     * @Template
     */
    public function pagesAction()
    {
        $em = $this->getDoctrine()->getManager();
        // Note that we fetch from AdminBundle
        $pages = $em->getRepository('AcmeAdminBundle:Page')->findAll();

        return array('pages' => $pages);
    }
}

This controller is matched on http://example.com/pages
This would fetch the pages of your AdminBundle entity.

Admin Panel

Now that you want an admin panel, you can create another bundle which contains only this logic.
This bundle has its own controllers and views which can be used by the whole application

project/
    src/
        Acme/
            FrontBundle/
            AdminBundle/
                Controller/
                    PagesController.php
                Entity/
                    Page.php
                Resources/
                    views/
                        Pages/
                            add.html.twig
                            edit.html.twig
                        layout.html.twig
                Services/
                    AdminAuth/
                    AdminCore/

Services

Here's your logic classes where you want to add your some of your components.
Read more about Services

Entity

Read about doctrine entities

Controller

Acme\AdminBundle\Controller\PagesController

<?php

namespace Acme\AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
 * @Route("/admin/pages")
 */
class PagesController extends Controller
{
    /**
     * @Route("/edit")
     * @Template
     */
    public function editAction()
    {
        // Edit
    }

    /**
     * @Route("/add")
     */
    public function addAction()
    {
        // Add
    }
}

The edit action would match on http://example.com/admin/pages/edit
The add action would match on http://example.com/admin/pages/add

Further reading

Community
  • 1
  • 1
Touki
  • 7,465
  • 3
  • 41
  • 63