logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$20
How to show many-to-many relationship as checkboxes?

Symfony 1.4 using Propel.

If I look in BasesfGuardPermissionForm.class.php I see this:

abstract class BasesfGuardPermissionForm extends BaseFormPropel
{
public function setup()
{
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'name' => new sfWidgetFormInputText(),
'description' => new sfWidgetFormTextarea(),
'sf_guard_group_permission_list' => new sfWidgetFormPropelChoice(array('multiple' => true, 'model' => 'sfGuardGroup')),
'sf_guard_user_permission_list' => new sfWidgetFormPropelChoice(array('multiple' => true, 'model' => 'sfGuardUser')),
));


For sf_guard_user_permission_list, this seems to manage a many-to-many relationship and show it as multiple choice. I'd like to do something similar, but render the choices as checkboxes.

I have a deal model that looks like this:

  
deal:
id:
app_id: { type: integer, required: true, foreignTable: app, foreignReference: id, onDelete: cascade }
title: varchar(255)
deal: varchar(255)
original_price: integer
discounted_price: integer
starts_at: timestamp
ends_at: timestamp
place_id: { type: integer, required: false, foreignTable: place, foreignReference: id, onDelete: cascade }
limited_to: integer
is_recurring: boolean
push_before_sec: integer
push_text: longvarchar
image: varchar(255)
description: longvarchar
notification_id: { type: integer, required: false, foreignTable: notification, foreignReference: id, onDelete: cascade }



There is also a database table called 'weekday' and this table has just 7 rows in it, with the 7 days of the week. In between those 2 models is a "deal_weekday" model:

  deal_weekday:
weekday_id: { type: integer, primaryKey: true, required: true, foreignTable: weekday, foreignReference: id, onDelete: cascade }
deal_id: { type: integer, primaryKey: true, required: true, foreignTable: deal, foreignReference: id, onDelete: cascade }
created_at:


When I look at the form for the Deals, I need to also have the 7 weekdays appear as checkboxes. How do I do this?

Lawrence Krubner | 11/14/12 at 5:01pm Edit
Tutorial: How to assign prize money


(2) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    11/14/12
    9:25pm
    mullerivan says:

    In the form try this




    $this->setWidget('WIDGET_NAME_RELATION' ,new sfWidgetFormPropelChoice(array('model' => 'WeekDay')),

    $this->getWidget('WIDGET_NAME_RELATION')->setOption('expanded',true);
    $this->getWidget('WIDGET_NAME_RELATION')->setOption('multiple',true);

    Previous versions of this answer: 11/14/12 at 5:15pm | 11/14/12 at 5:17pm | 11/14/12 at 5:23pm | 11/14/12 at 5:23pm | 11/14/12 at 9:25pm | 11/14/12 at 9:25pm | 11/14/12 at 9:25pm

  • avatar
    Last edited:
    11/14/12
    5:32pm
    Milena Dimitrova says:

    You can add this to the configure() method in your DealForm class:


    $weekdays = WeekdayPeer::doSelect(new Criteria());
    $weekdayChoices = array();
    foreach ($weekdays as $weekday)
    {
    $weekdayChoices[$weekday->getId()] = $weekday->getName();
    }
    $this->setWidget('deal_weekdays', new sfWidgetFormSelectCheckbox(array('choices' =>$weekdayChoices )));
    $this->setValidator('deal_weekdays', new sfValidatorPass());



    Once added, do not forget to also add the new widget 'deal_weekdays' to appear by adding it in generator.yml for actions 'edit' and 'new'.

    Note: This will make the checkboxes appear but you will have to save them automatically.

This question has expired.





Current status of this question: Community pot



Please log in to add additional discourse to this page.





Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.