Create a component. In your product template :
<?php if ($product->canBeAlerted()): ?>
<?php include_component('product', 'alert', array('product_id' =>
$productId)); ?>
<?php endif ?>
Create your component in components.class.php, with your code :
<?php
class productComponents extends sfComponents
{
public function executeAlert(sfWebRequest $request)
{
//... create your form, you have product_id
}
}
And template, with echo $form
Look at documentation for more informations about components
2010/8/15 Gabriel Comeau <[email protected]>
> Hello all,
>
> I'm fairly new to to Symfony and have a structural question of sorts. I
> have a problem with a few ideas of how to solve, but they don't seem very
> elegant and I'm looking to hear from someone more experienced with the
> framework who can point me in the direction of a cleaner solution. I'm
> using Symfony 1.4 with the Doctrine ORM.
>
> Background:
>
> My application is a typical store: catalog / shopping cart combination.
> My client sells imported collector's items, and usually buys the
> merchandise in person on trips to Asia, so when something goes out of stock
> it can be quite a while before more is available. To this end, items which
> are out of stock don't show up in the regular catalog listings or searches.
> They are still accessible with special categories and with a search option.
> We want our users to be able to submit their email addresses so that we can
> email them when a product becomes available again and so we can see which
> items are in high demand so we can plan our restocking out. So, I created
> two tables - oos_emails_pending and oos_emails_log. The first is the one
> I'm concerned with, it has:
>
> id
> item_id (fk constraint to the item id)
> email
> date_created
>
> I want to conditionally add a form to our 'detail view' for items with
> inventory==0 to allow users to enter their email address to add an entry to
> this table.
>
> The problem:
>
> Since the template that I want to show this form is called from an Item
> action, I'm not sure how to get it to use a form for another model. The
> solutions I have come up with are:
>
> Redirect the user to a new module/action and pass the item_id along as a
> request parameter.
> Make the form part of a component, so it can use a different model.
>
> Neither of them seem ideal, and before I pursue one, I'd like to hear from
> people who are more experienced. Any advice would be greatly appreciated!
>
> Thanks,
>
> Gabriel Comeau
>
> --
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]<symfony-users%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>
--
Alexandre Salomé
http://alexandre-salome.fr
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en