Wednesday, August 25, 2010

sfDoctrinePager: Fatal error: Call to undefined method Doctrine_Collection::offset()

If you set a sfDoctrinePager object and give an EXECUTED query to the $this->pager->setQuery() method, you get a fatal error. Don't forget, sfDoctrinePager will execute the query, not you. Remove the ->execute() command from the end of the query.

Fatal error: Call to undefined method Doctrine_Collection::offset() in C:\webserv\www\phpcrm\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\pager\sfDoctrinePager.class.php on line 84

Text-Overflow in Table Cell

Really really long text to trim...

Friday, August 13, 2010

Download Files via Action in Symfony

public function executeDownload(sfWebRequest $request)
   $response = $this->getContext()->getResponse();
   $response->addCacheControlHttpHeader('Cache-control','must-revalidate, post-check=0, pre-check=0');
   $response->setHttpHeader('Content-Transfer-Encoding', 'binary', TRUE);
   $response->setHttpHeader('Content-Disposition','attachment; filename='.$request->getParameter('filename'), TRUE);
   return sfView::NONE;
This action requires a 'directory' and a 'filename' parameter.

Thursday, August 12, 2010

Old Nusoap Syntax can cause SOAP Error in PHP5

It is related to PHP5, which object names collides with the new soapclient() syntax (the PHP SOAP extension uses the same object name). If you change your syntax in the constructor from "new soapclient()" to "new nusoap_client()", the collision won't happen - and everything will be happy. Nusoap keeps the old syntax for legacy support ("new soapclient"). But PHP5 won't like it and give you a nice error:

Warning: SoapClient::SoapClient() expects parameter 2 to be array, boolean
given in /var/www/userdetails.php
on line 76

Fatal error: Uncaught SoapFault exception: [Client]
SoapClient::SoapClient() [soapclient.soapclient]: Invalid
parameters in
/var/www/userdetails.php:76 Stack
trace: #0
SoapClient->SoapClient('https://195.228...', true) #1
/var/www/index.php(48): include('/var/www/i...') #2
{main} thrown in
/var/www/userdetails.php on line 76

Wednesday, August 4, 2010

JSON Response in Symfony

If you want an action returns with json data, create something like this:
public function executeJson(sfWebRequest $request)
   // create the data
   $data = "something";
   return $this->renderText(json_encode($data));

Tuesday, August 3, 2010

Redirect to Referer in Action in Symfony


Validating Integers without Regular Expression in PHP

ctype_digit checks if all of the characters in the provided string are numerical. Therefore, you must convert variables to string first, then you check them with ctype_digit.
$array = array(5, 5.2, "456", "564-223", "5.2", "673");
foreach($array as $item) {
   if(ctype_digit((string)$item)) {
      echo "int: ".$item."\n";
   } else {
      echo "not int: ".$item."\n";

Monday, August 2, 2010

Delete embed forms/objects in Symfony

First of all, you have to add a delete checkbox to the embedded form:
// lib/form/doctrine/ formclass -> configure()
if ($this->object->exists())
   $this->widgetSchema['delete'] = new sfWidgetFormInputCheckbox();
   $this->validatorSchema['delete'] = new sfValidatorPass();
Don't forget to echo the 'delete' form widget in the template. Now open the form class which embed the other form. You have to overwrite some basic methods. The code below is used and created by me, but perhaps you won't be able to use/understand. Please, first check the the following blog entry: Embedding Relations in Forms with Symfony 1.3 and Doctrine
public function saveEmbeddedForms($con = null, $forms = null)
  if (null === $forms)
   $notes = $this->getValue('newNotes');
   $forms = $this->embeddedForms;
   foreach ($this->embeddedForms['newNotes'] as $name => $form)
    if (!isset($notes[$name]))
  foreach ($forms as $form)
    if ($form instanceof sfFormObject)
   if (!in_array($form->getObject()->getId(), $this->scheduledForDeletion))
   $this->saveEmbeddedForms($con, $form->getEmbeddedForms());

  protected function doBind(array $values)
    if (isset($values['Notes']))
      foreach ($values['Notes'] as $i => $noteValues)
        if (isset($noteValues['delete']) && $noteValues['id'])
          $this->scheduledForDeletion[$i] = $noteValues['id'];
  protected function doUpdateObject($values)
    if (count($this->scheduledForDeletion))
      foreach ($this->scheduledForDeletion as $index => $id)