I work on a Symfony1 application.
For part of the application we use the symfony admin generator which builds default actions and templates for a particular module.
The autogenerated action methods can be overridden in the child action class and the templates can be overridden, by making one with the same name in the module's template folder. Local templates are used instead of the autogenerated ones, which are stored in a cache folder (I assume this is normal symfony behaviour).
apps/
my_app
modules/
post/
actions/
actions.class.php
lib/
templates/
...
cache/
my_app/
environment/
modules/
autoPostcd /
actions/
actions.class.php
lib/
templates/
indexSuccess.php
_part_1.php
_part_2.php
I am currently working on a separate application that is not using the admin generator.
But I have 3 modules that do very similar things, that I would like to share.
I have all 3 actions extending the same custom action class so that they all implement the same methods and share the ones that are identical.
The problem that I am having is sharing the templates. The main templates and most of the partials can be reused as is.
apps/
other_app/
lib/
printingActions.class.php
modules/
ticket/
actions/
actions.class.php
lib/
templates/
printSuccess.php //exactly the same for all 3
_part_1.php
_part_2.php //exactly the same for all 3
_part_3.php
receipt/
actions/
actions.class.php
lib/
templates/
printSuccess.php //exactly the same for all 3
_part_1.php
_part_2.php //exactly the same for all 3
_part_3.php
voucher/
actions/
actions.class.php
lib/
templates/
printSuccess.php //exactly the same for all 3
_part_1.php
_part_2.php //exactly the same for all 3
_part_3.php
What I would like to do is pull out the common ones so that each module and any future modules with a similar interface, only have to have the partials with module specific information.
This would be my ideal setup:
apps/
other_app/
lib/
printingActions.class.php
printingCommonTemplates/
printSuccess.php //exactly the same for all 3
_part_2.php //exactly the same for all 3
modules/
ticket/
actions/
actions.class.php
lib/
templates/
_part_1.php
_part_3.php
receipt/
actions/
actions.class.php
lib/
templates/
_part_1.php
_part_3.php
voucher/
actions/
actions.class.php
lib/
templates/
_part_1.php
_part_3.php
I know this kind of thing can be done, since the admin generator does it, but after hours of digging, I can't find where exactly it does it.
Could someone point me in the right direction for this one? Ideally, if there is a fallback template setting that I can set for a particular module or a filter class that I can extend to do what I need?
If you want to use a common module action class with a default layout you can use the following approach:
class printingActions extends sfActions {
public function preExecute() {
$this->setLayout('print_success_common');
}
public function executeIndex() {
}
}
Then in your module action you may have:
class ticketActions extends printingActions
{
public function executePrint(sfWebRequest $request)
{
$this->txt = 1234;
return $this->renderPartial('part_1', array('txt' => $this->txt));
}
}
You can use a different(common) layout from your action by using:
class ticketActions extends printingActions
{
public function executePrint(sfWebRequest $request)
{
$template = $this->getContext()->getConfiguration()->getTemplateDir('printing', 'print_success_common_alt.php');
$this->setLayout($template . '/print_success_common_alt');
...
$this->txt = 1234;
return $this->renderPartial('part_1', array('txt' => $this->txt));
}
}