9

Is there the way to use sonata admin bundle without entity - so without doctrine?

I need to list files on some directory, this list is not stored in database.

The first approach I tried was to declare my own Model manager, but there are some places which require doctrine queries etc.

I know, that there is document manager for mongo and sonata mongo admin, but in my case it's not so helpful.

Any ideas?

falinsky
  • 7,229
  • 3
  • 32
  • 56
  • Is listing the files all that you need to do? If so, you shouldn't need to create a Sonata Admin class to do so. Just use any of the number of available methods in PHP for interacting with directories. – dyelawn Jan 04 '14 at 22:40
  • @dyelawn nope, I need to have ability of sorting and filtering results – falinsky Jan 06 '14 at 09:57
  • I was asking the same question on SO, the answer was : http://stackoverflow.com/questions/38221948/how-to-create-a-custom-action-not-related-to-entity-from-sonata-admin – Tsounabe Oct 27 '16 at 17:11
  • You can look at this link : http://stackoverflow.com/questions/15966575/sonataadminbundle-display-non-crud-statistics/22507027 – Tsounabe Oct 27 '16 at 17:22

1 Answers1

4

In the documentation found here: http://sonata-project.org/bundles/admin/master/doc/reference/getting_started.html

It looks like in the create an admin section that #2 requires a model:

  1. The Admin service’s code (defaults to the service’s name)
  2. The model which this Admin class maps (required)
  3. The controller that will handle the administration actions (defaults to SonataAdminBundle:CRUDController)

The sample shows the service setup with manager_type as an ORM:

# Acme/DemoBundle/Resources/config/admin.yml
services:
    sonata.admin.post:
        class: Acme\DemoBundle\Admin\PostAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Content", label: "Post" }
        arguments:
            - ~
            - Acme\DemoBundle\Entity\Post
            - ~
        calls:
            - [ setTranslationDomain, [AcmeDemoBundle]]

Now in general symfony doesn't set hard requirements on what a model is. It can be doctrine or something custom you build. In the case of services it is just an object. I don't see anywhere in the documentation says that you need a database.

Shawn
  • 3,583
  • 8
  • 46
  • 63
  • so do you know any good documentations about creating custom models? – falinsky Jan 06 '14 at 10:00
  • 2
    @falinsky Symfony is not a MVC model in the traditional sense. As long as you have a class object you can do anything with it. This symfony article explains how to setup a class as a service. This may get you in the right direction, as it explains a bit about what I am saying. http://symfony.com/doc/current/book/service_container.html – Shawn Jan 06 '14 at 21:52
  • 2
    you just explain basical things... they are not helpful for my situation. you'd understand that we talk about sonata admin bundle, not just symfony in general – falinsky Jan 06 '14 at 23:36
  • 2
    Well I can't write the code for you here as your case is very specific and would take a good bit of development, I have given you the info and tools to do what you need. Basically, if you have a code class that has functionality it can be registered as a service. So register the class, this service in your case would be your "model". The link I gave you explains a mailer class being used as a service. This is very similar to how that bundle works, as it shows you a controller and the service and how to use them in an example. – Shawn Jan 06 '14 at 23:41
  • did you find a workaround ? I am trying to use objects in admin class that are coming from custom query and custom hydratation. When i define the entity class in the admin service, as it's not an orm class, i can't it. It throws an error. (getMetadata) – Rmannn Sep 16 '14 at 14:02