You have to pass a Doctrine query to the widget, not a Doctrine collection.
(Note the "Query" part in my getCampaignsQuery() table method example.)
Samuel Morhaim wrote:
Syam.. that didnt work it gives me an error.
$query =
Doctrine::getTable('Campaign')->getCampaigns(sfContext::getInstance()->getUser()->getGuardUser()->Organization);
$this->widgetSchema['campaign_id'] = new
sfWidgetFormDoctrineChoice(array
(
'model' => 'Campaign',
'query' => $query
));
*Fatal error*: Call to undefined method Doctrine_Collection::execute()
in
*/usr/local/share/symfony-1.4/lib/plugins/sfDoctrinePlugin/lib/widget/sfWidgetFormDoctrineChoice.class.php*
on line *86
*Let me know..
I went around it by adding INDEXBY to the query... but i dont think
its clean to do it this way without using the doctrine widget.
public function getCampaigns(Organization $organization = null)
{
$q = Doctrine_Query::create()
->from('Campaign c INDEXBY c.id <http://c.id>')
->where('c.organization_id =?', $organization->id);
return $q->execute();
}
On Sat, Mar 6, 2010 at 8:44 AM, Syam <s...@nexen.org
<mailto:s...@nexen.org>> wrote:
Hi,
You can use the sfWidgetFormDoctrineChoice widget with the 'query'
option, thus, you can pass params to your query throught the form
option system :
*In action :*
$this->form = new campaignForm($record, array('organization' =>
$user->organization) // or any param you want from $request object
*In form :*
$query =
Doctrine::getTable('Campaign')->getCampaignsQuery($this->getOption('organization'))
$this->widgetSchema['campaign_id'] = new
sfWidgetFormDoctrineChoice(array
(
'model' => 'Campaign',
'query' => $query
));
Hope it help you.
Samuel Morhaim wrote:
I have a question, I have a dropdown that needs to be populated
from the database, but with a query, and the query is based on a
post variable.
I know that sfWidgetFormDoctrineChoice has an option for passing
a method, but I can't pass a method + parameter like that.
So I used the simple sfWidgetFormChoice with the choice value
being the Doctrine getTable and the parameter.. as shown in the
bottom of this email.. HOWEVER, the dropdown is not well
populated. The dropdown is formed like this:
<option value="0">20 Off Code</option>
<option value="1">Special Sale</option>
<option value="2">30 Off</option>
This is incorrect, since the value for 20 Off Code is not 0 , is
actually 1 so the index is wrong.
$this->widgetSchema['campaign_id'] = new sfWidgetFormChoice(array
(
'choices' =>
Doctrine::getTable('Campaign')->getCampaigns(sfContext::getInstance()->getUser()->getGuardUser()->Organization)
));
What can I do ?
Thank you.
--
If you want to report a vulnerability issue on symfony, please
send it to security at symfony-project.com
<http://symfony-project.com>
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to
symfony-users@googlegroups.com
<mailto:symfony-users@googlegroups.com>
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
<mailto:symfony-users+unsubscr...@googlegroups.com>
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
--
If you want to report a vulnerability issue on symfony, please
send it to security at symfony-project.com
<http://symfony-project.com>
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to
symfony-users@googlegroups.com <mailto:symfony-users@googlegroups.com>
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
<mailto:symfony-users%2bunsubscr...@googlegroups.com>
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
--
If you want to report a vulnerability issue on symfony, please send it
to security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en