Tuesday, August 16, 2011

Get the Label Text of a Form Field in Symfony

$form->getWidgetSchema()->getLabel('fieldname')

Friday, August 12, 2011

Check Symfony Environment in Javascript

function prefix() {
  return window.location.href.indexOf('frontend_dev.php') != -1 ? '/frontend_dev.php' : '';
}

function example() {
  window.open(prefix()+'/module/action');
}

Thursday, August 11, 2011

Login Automagicly to phpMyAdmin 3.4

Change the config.inc.php file...

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'YOUR USER';
$cfg['Servers'][$i]['password'] = 'YOUR PASSWORD';

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');