symfony-cmf / simple-cms-bundle

UNMAINTAINED - A more-than-simple cms based on the cmf components
http://cmf.symfony.com/
49 stars 45 forks source link

Multiple documents best practice #110

Closed lowki closed 10 years ago

lowki commented 10 years ago

Hi, I have two different documents to manage, pages and products. And I would like to have a tree like this.

/cms/simple
  /page1
  /page2
  /page3
  /products
      /product1
      /product2
      /product3

So I have a few questions :

  1. Is it possible to have multiple documents extending the SimpleCmsBundle/Page, so I would be able to render my documents through different templates?
  2. How will the automatic routing should be configured?
  3. I think it's easier to use the document class for both pages and products, but then, how can I render them through different templates?
dbu commented 10 years ago
  1. you can have several documents extending the same base document
  2. if you mean templates_by_class it works just the same as with documents that do not extend each other. just keep in mind that the matching is instanceof so you need to put the child classes first and the parent after.
  3. i would not use the same class, it makes it confusing for the users of your system.

ideally, you never use Page directly but only your custom extended page or the product. then you define one admin per class. if you keep the SimpleCms Page admin in the system, its list will list you all extending documents mixed together and try to edit those, which is not helpful. (a shortcoming of sonata admin, see https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/80 for further reference)

dbu commented 10 years ago

btw, you can also have your Admin extend the simplecms admin and just add the missing fields. sonata admin even has a method to reorder those fields, should you need that.

lowki commented 10 years ago

Ok, the doc says this about extending

cmf_simple_cms:
    persistence:
        phpcr:
            document_class: Acme\DemoBundle\Document\MySuperPage

So, could I use many of them?

dbu commented 10 years ago

this is only if you want to use the default setup with a custom class. if your MySuperPage has additional fields, you would also need a custom admin and set that with the admin_class.

what you need to do is define a second admin for your other document. you can look at the service definitions of SimpleCmsBundle to get inspiration, or read up in the sonata documentation how you do your own admins.

lowki commented 10 years ago

I think I've made it through. As soon as my knowledge permit it, I enhance the doc about this. Thank you one more time David.

dbu commented 10 years ago

you are welcome! looking forward to doc updates.