예제 #1
0
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $default_buttons = array('add_file' => 'Add files...', 'upload' => 'Start upload', 'cancel' => 'Cancel upload');
     $buttons = $this->getOption('buttons') + $default_buttons;
     $module_partial = $this->getOption('module_partial');
     if ($module_partial) {
         sfApplicationConfiguration::getActive()->loadHelpers('Partial');
         include_partial($module_partial, array('widget' => $this, 'name' => $name, 'value' => $value, 'attributes' => $attributes, 'errors' => $errors, 'buttons' => $buttons));
     } else {
         $context = sfContext::getInstance();
         $view = new sfPartialView($context, '', '', '');
         $plugin_path = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . 'laWidgetFileUploadPlugin';
         $view->setTemplate($plugin_path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . '_upload_widget.php');
         $view->setPartialVars(array('widget' => $this, 'buttons' => $buttons));
         echo $view->render();
     }
 }
예제 #2
0
/**
 * Evaluates and returns a partial.
 * The syntax is similar to the one of include_partial
 *
 * <b>Example:</b>
 * <code>
 *  echo get_partial('mypartial', array('myvar' => 12345));
 * </code>
 *
 * @param  string $templateName  partial name
 * @param  array  $vars          variables to be made accessible to the partial
 *
 * @return string result of the partial execution
 * @see    include_partial
 */
function get_partial($templateName, $vars = array())
{
    $context = sfContext::getInstance();
    // partial is in another module?
    if (false !== ($sep = strpos($templateName, '/'))) {
        $moduleName = substr($templateName, 0, $sep);
        $templateName = substr($templateName, $sep + 1);
    } else {
        $moduleName = $context->getActionStack()->getLastEntry()->getModuleName();
    }
    $actionName = '_' . $templateName;
    $view = new sfPartialView($context, $moduleName, $actionName, '');
    $view->setPartialVars($vars);
    return $view->render();
}