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.


Solution:
  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()): ?]

    to:

    [?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() ?>'));

    to:

    $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: http://www.symfony-project.org/plugins/sfCKEditorPlugin
  3. Go to http://ckeditor.com/ and download the last version.
  4. Put the ckeditor folder to the web\js folder.
  5. Go to http://ckfinder.com/ 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
      ckeditor:
        basePath: /js/ckeditor
      ckfinder:
        active: true
        basePath: /js/ckfinder
  9. Create autoload.yml file and put:

    autoload:
      ckeditor:
        name:       ckeditor
        path:       %sf_web_dir%/js/ckeditor
        recursive:  on
       
      ckfinder:
        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 =
    [
        ['Source'],
        ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'Templates'],
        ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
        '/',
        ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
        ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
        ['Link','Unlink','Anchor'],
        '/',
        ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
        ['Format','FontSize'],
        ['TextColor','BGColor']
    ];

Friday, September 3, 2010

Convert Table Character Set in Mysql

for example...
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

Wednesday, September 1, 2010

How to Manage MySQL Table Names with #__ Prefix

Every time you make a query from a table that has a special #__ prefix, you need to put table name between `` signs.
INSERT INTO `#__session` ...
Otherwise it won't work and give you a meaningless error:

MySQL query error, please check your configuration! You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

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