1

在 CodeIgniter 中,我使用的是 HMVC 扩展,我可以为我的模块使用这种结构:

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

这允许我将管理部分包含到我的模块中并将其调用到 admin_core 和 admin_menu 模块。

这里有更多细节(最后一种方法)解释:

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

可以在 Symfony2 中完成类似的事情,如果可以,我可以在哪里找到一些教程如何实现类似的结构,因此模块包含管理部分(控制器和视图)。我正在寻找,但我没有找到类似的东西。

有没有一本书详细讨论过这个问题,如何使用包含 amdin 部件的模块创建管理员?

4

1 回答 1

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

于 2013-08-13T09:11:04.973 回答