Showing posts with label action. Show all posts
Showing posts with label action. Show all posts

Wednesday, February 22, 2012

url_for Helper in Action in Symfony

$this->getContext()->getConfiguration()->loadHelpers(array('Url'));
// now you can use url_for()

Tuesday, February 21, 2012

Parse YML (Yaml) Files In Action in Symfony

$myarray = sfYaml::load(sfConfig::get('sf_config_dir').'/myconf.yml');

Thursday, October 6, 2011

Clear Cache from Action in Symfony

/**
 * Delete cache for application and environment
 *
 * @param string $app aplicación
 * @param string $env entorno
 */
function clear_cache ($app, $env)
{
  $cacheDir = sfConfig::get('sf_cache_dir').'/'. $app.'/'.$env.'/';

  //Clear cache
  $cache = new sfFileCache(array('cache_dir' => $cacheDir));
  $cache->clean();
}

Wednesday, August 3, 2011

Generate an Excel file with sfPhpExcel in Symfony

  public function executeExcel(sfWebRequest $request)
  {
    // We're not going to be displaying any html, so no need to pass the data through the template
    $this->setLayout(false);

    // Initialize the Excel document
    $obj = new PHPExcel();
       
    // Set the active excel sheet
    $obj->setActiveSheetIndex(0);
    
    $obj->setActiveSheetIndex(0);
    $obj->getActiveSheet()->setCellValue('A1', 'Hello');
    $obj->getActiveSheet()->setCellValue('B2', 'world!');
    $obj->getActiveSheet()->setCellValue('C1', 'Hello');
    $obj->getActiveSheet()->setCellValue('D2', 'world!');
    
    // Output the excel data to a file
    $filePath = realpath('./excel') . DIRECTORY_SEPARATOR . 'excel.xlsx';
    $writer = PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
    $writer->save($filePath);
    
    // Redirect request to the outputed file
    $this->getResponse()->setHttpHeader('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    $this->redirect('/excel/excel.xlsx');
  }

Tuesday, August 2, 2011

Calling the i18n Function __() in an Action in Symfony

$this->getContext()->getI18N()->__($text, $args, 'messages');

Tuesday, March 29, 2011

Disable the Web Debug Toolbar in an Action in Symfony

Simply use...
sfConfig::set('sf_web_debug', false);