Páginas

29 de agosto de 2011

Propel get average - mysql AVG

Here's how to do it:

public function getAverageRating()
  {
    $c = new Criteria;
    $c->addSelectColumn('avg(' . RatingPeer::RATING . ')');
    $c->add(RatingPeer::ID, $this->getId());
    
    $stmt = RatingPeer::doSelectStmt($c);    
    $average = $stmt->fetchAll(PDO::FETCH_COLUMN);
    if(array_key_exists(0, $average)) {
      return floatval($average[0]);
    }
    else
    {
      return 0;
    }
  }

26 de agosto de 2011

Using CKEditor and CKFinder


+

  1. Download the sfCKEditorPlugin plugin
  2. Go to http://ckeditor.com/ and download the last version.
  3. Put the ckeditor folder to the web\js folder.
  4. Go to http://ckfinder.com/ and download the last version.
  5. Put the ckfinder folder to the web\js folder.
  6. Add sfCKEditorPlugin to the ProjectConfiguration.class.php
  7. Open app.yml (apps/frontend or backend/config..) and put:
      # sfCKEditorPlugin
      ckeditor:
        basePath: /js/ckeditor
      ckfinder:
        active: true
        basePath: /js/ckfinder
  8. Create config/autoload.yml:
    autoload:
      ckeditor:
        name:       ckeditor
        path:       %sf_web_dir%/js/ckeditor
        recursive:  on
        
      ckfinder:
        name:       ckfinder
        path:       %sf_web_dir%/js/ckfinder
        recursive:  on
  9. Add js files to the view.yml in this way:
    javascripts: [ckeditor/ckeditor.js, ckfinder/ckfinder.js]
  10. Edit /js/ckfinder/config.php... find CheckAuthentication() method and modify it toreturn true; however read the comments, it can be dangerous!
  11. Change the $baseUrl to /uploads/ckfinder/ in ckfinder's config.php
  12. Type symfony cc to clear the cache.
  13. Use the following syntax to call CKEditor:
    $this->widgetSchema['my_editor'] = new sfWidgetFormCKEditor();


From: http://sakrawebstudio.blogspot.com/2010/10/install-ckeditor-and-ckfinder-in.html

1 de agosto de 2011

Where did a certain query originated?

Easy way of tracking every sql query under sf's the web debug toolbar:

#factories.yml:
dev:
  logger:
    param:
      loggers:
        sf_web_debug:
          param:
            xdebug_logging: true

Result: