Friday, October 29, 2010

SQLSTATE[HY000]: General error: 1005 Can't create table

Let's see a very simple CORRECT relation and reasons why it can throw SQLSTATE[HY000]: General error...

      foreignAlias: Phonenumbers
      local: user_id
      foreign: id
      type: one
      foreignType: many

  1. Did you forget to define the user_id field in the Phonenumber table?
  2. Did you check the type of the user_id field and the Phonenumber table's id field? They must be exactly the same integer. If one of them is int(4) and the other is int(8), the building will fail.

Thursday, October 28, 2010

Remove PostValidator in Symfony

Remove post validator that is set in a base form:

$this->validatorSchema->setPostValidator(new sfValidatorPass()); 

Tuesday, October 26, 2010

generator.yml: Related Object's Fields in the DISPLAY List

If you want to show only the name (default field) of a related object, you can use the name of the object:

[id, name, Category]

This case Category will return with $this->getCategory()->getName() where $this is the current object. For other fields, create simple functions on the model class. Ex.:

// lib/model/doctrine/Article.class.php
public function getCategoryDescription()
  return $this->getCategory()->getDescription();

Now put this to the display list:

[id, name, category_description]

Wednesday, October 13, 2010

_csrf_token [CSRF attack detected.] error using sfAdminThemejRollerPlugin

If you try to do a batch delete with the Choose an option form, you can get a CSRF attack detection error using the sfAdminThemejRollerPlugin 0.2.0beta plugin.

  1.  Edit plugins/sfAdminThemejRollerPlugin/data/generator/sfDoctrineModule/jroller/template/templates/_list_batch_actions.php and change line 9 from:

    [?php $form = new sfForm(); if ($form->isCSRFProtected()): ?]


    [?php $form = new BaseForm(); if ($form->isCSRFProtected()): ?]
  2. Edit plugins/sfAdminThemejRollerPlugin/data/generator/sfDoctrineModule/jroller/parts/batchAction.php and change line 29 from:

    $validator = new sfValidatorDoctrineChoice(array('model' => '<?php echo $this->getModelClass() ?>'));


    $validator = new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => '<?php echo $this->getModelClass() ?>'));
  3. Type symfony cc to clear the cache.

Install CKEditor and CKFinder in Symfony

  1. Create the sfCKEditorPlugin folder in the Plugins folder.
  2. Download package:
  3. Go to and download the last version.
  4. Put the ckeditor folder to the web\js folder.
  5. Go to and download the last version.
  6. Put the ckfinder folder to the web\js folder.
  7. Add sfCKEditorPlugin to the ProjectConfiguration.class.php
  8. Open app.yml (apps/frontend or backend/config..) and put:

      # sfCKEditorPlugin
        basePath: /js/ckeditor
        active: true
        basePath: /js/ckfinder
  9. Create autoload.yml file and put:

        name:       ckeditor
        path:       %sf_web_dir%/js/ckeditor
        recursive:  on
        name:       ckfinder
        path:       %sf_web_dir%/js/ckfinder
        recursive:  on
  10. Add  js files to the view.yml in this way:
    javascripts:    [ckeditor/ckeditor.js, ckfinder/ckfinder.js]
  11. Edit /js/ckfinder/config.php... find CheckAuthentication() method and modify it to return true; however read the comments, it can be dangerous!

    My solution: In production you will need to add a special cookie to the authenticated users, ex. imgupload... in this case you can use return isset($_COOKIE['imgupload']); in the function.
  12. Change the $baseUrl to /js/ckfinder/userfiles/ in config.php
  13. Type symfony cc to clear the cache.
  14. Use the following syntax to call CKEditor:
    $this->widgetSchema['my_editor'] = new sfWidgetFormCKEditor();
  15. I usually change the ckeditor interface. I remove the h1 tag and the unused functions. Try to put this to the ckeditor/config.js and refresh the browser window:

    CKEDITOR.editorConfig = function( config )
        //config.language = 'hu';
        config.format_tags = 'p;h2;h3;h4;h5;h6';
        config.height = 500;

        config.entities = false;
        config.disableNativeSpellChecker = false;
        config.scayt_autoStartup = false;

    CKEDITOR.config.toolbar_Full =
        ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'Templates'],