Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "partial"

Render partials in a Task

I needed to send emails from a task using partials. The technique for SF 1.3/4 is explained in the docs, but how to get links to render properly is not. I found some good info on the web that was a bit hidden. Here is what it lead me to come up with.

To be able to use partials you need to set the context correctly:

sfContext::createInstance($this->configuration);
 

Since tasks don't have a url as their base for the request, helpers like url_for and link_to won't work correctly and output things like "/symfony/symfony/mymodule/myaction".

to remedy this I created a helper:

class batchHelpers
{
  public static function url_for($str)
  {
    $url = 'http://'.
            sfConfig::get('app_server_url','www.kaizengine.com') .
            sfContext::getInstance()->getController()->genUrl($str);
 
    return $url;
  }
}
 

the define for the "server_url" is in app.yml

Then in the partial I used this code to call get a correctly generated url:

batchHelpers::url_for('/home', true), array(
          'style'=>"text-decoration:none;margin:0;")
          );
 

I also render the same partial (with the same url_for replacement) inside the web interface and since the urls are absolute, they work correctly.

by Alex Knol on 2010-10-26, tagged email  partial  task  urlfor 
(2 comments)

PG4sfGuard(1): Partial for sfGuardUserProfile and sfGuardUser

If you want add a column to sfGuardUserProfile's list view for show a link to sfGuardUser's edit view:

Create a partial : site.com/apps/backend/modules/sf_Guard_User_Profile/templates/_user.php

And put this:

<?php echo link_to($sf_guard_user_profile->getSfGuardUser()->getUsername(), 'sfGuardUser/edit?id='.$sf_guard_user_profile->getSfGuardUser()->getId()) ?>

PD(It's not very much, but it is my first snippet)

by Roberto G Puentes Diaz on 2008-01-22, tagged generator  partial  sfguard 

Including custom partials in admin generator pages

Here is a method i developed to include some custom partials at the end of the edit action of a module which adapts admin generator.

i just added this at the end of editSuccess.php file of my generator theme ($sf_data_dir/generator/sfPropelAdmin/<myCustomTheme>/templates/editSuccess.php)

[?php // include xtra partials ?]
<?php if ($this->getParameterValue('edit.partials')): ?>
<?php
$partials = $this->getParameterValue('edit.partials');
foreach( $partials as $partial => $vars ) : ?>
[?php include_partial('<?php echo $this->getModuleName() ?>/<?php echo $partial ?>', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?> <?php foreach ($vars as $var): ?> , '<?php echo $var ?>' => $<?php echo $var; endforeach; ?>)); ?]
<?php endforeach; ?>

then you just have to add the partials in the generator.yml like this :

edit:
  partials:
    partial1: [ var1a, var1b ]
    partial2: [ var2a, var2b ]

where var.. are the variables you want to include in each partial.

this can be easily made for list success also.

by Kostas Papadimitriou on 2007-01-08, tagged admin  custom  generator  include  partial  partials 
(2 comments)