LyraAdminBundle
LyraAdminBundle copied to clipboard
four question about widget
hi
1.how to add dropdown list widget to form 2.how to fiter grid using combo box( dropdown list) 3.how to filter grid using special value( which field does not showed in grid ) 4.how to upload/show image in form
thanks a lot.
- I think you want to add a choice Field Type to a form. Try this:
lyra_admin:
models:
my_model:
fields:
myField:
widget: choice
options:
choices: ['choice1','choice2']
Let me know if this is not what you need.
-
If I got your question right it's not possible out of the box. You would need to create an additional search form and show it at the top of the list template, you would also probably need to override the model base controller with a custom one to manage a different filter action. It can be done, but it's probably not so easy given the current state of docs. I'll try to provide an example when I get some time (not in the next few days).
-
In the documentation (see Displaying associated model fields in list columns) you will find how to create a custom model manager for one of your models and override the method getBaseListQueryBuilder(): you can then add your own where clause to the list query builder.
-
Again not currently available out of the box. A possible solution is to create a custom FormType class for your model and a custom controller to manage the form. I'll try to implement something more easy.
I'm leaving this open, I'll consider these questions as suggestions for features to implement.
1)it shows the dropdown list , but how to set the values of choices, just like the code
$builder->add('gender', 'choice', array( 'choices' => array('m' => 'Male', 'f' => 'Female'), 'required' => false, ));
- I make 2 step, but the grid seems no change.
x\yBundle\Model\ListingManager.php:
namespace x\yBundle\Model;
use Lyra\AdminBundle\Model\ORM\ModelManager as BaseManager;
class ListingManager extends BaseManager { public function getBaseListQueryBuilder() { $qb = parent::getBaseListQueryBuilder(); $qb->select('a'); $qb->andWhere('a.mty = :mty')->setParameter('mty', 'KC');
return $qb;
}
}
service.xml:
<parameters>
<parameter key="x_y.listing_manager.class">x\yBundle\Model\ListingManager</parameter>
</parameters>
<services>
<service id="x_y.listing_manager" class="%x_y.listing_manager.class%">
</service>
</services>
lyra_admin:
models:
my_model:
fields:
myField:
widget: choice
options:
choices: {m: Male, f: Female}
- Is service.xml loaded by your bundle extension class? (See AcmeClassifiedsBundle if you need an example) Did you add this to your config:
lyra_admin:
models:
my_model:
# ... #
services:
model_manager: x_y.listing_manager
thanks, it works.
an advance question : how to filled the widget: choice if the values are dynamic( select from database)?