Friday, February 18, 2011

Calling Ajax

    $('select#procedure_mail_template_mail_type_id').live('change', function(){

function getMailTypeText(){
        url: $('input#getMailTypeText').val(),
        data: { mail_type_id:  $('select#procedure_mail_template_mail_type_id').val()},
        dataType: 'json',
        success: function(xhr){

Creating Options

Sample code:
public function configure()
 $user_id = sfContext::getInstance()->getUser()->getGuardUser()->id;
 $query = Doctrine_Query::create()
  ->from('UserFamily t')
  ->where('t.user_id=?', $user_id);
 $this->widgetSchema['user_family_id'] = new sfWidgetFormDoctrineChoice(array(
  'model'  => $this->getRelatedModelName('UserFamily'),
  'add_empty' => false,
  'query'  => $query,
  'method'    => 'getFullName',
 $this->widgetSchema['procedure_id'] = new sfWidgetFormInputHidden(array(), 
public function getFullName()
 $civilite = UserFamily::getCiviliteList();
 return $civilite[$this['civilite']].' '.$this['prenom'].' '.$this['nom'];  

Setting Value to a Form

Sample Code:
public function executeNew(sfWebRequest $request)
$this->forward404Unless($procedure_mail_template = $request->getParameter('procedure_id'), sprintf('Procedure Mail Template is not defined (%s).', $request->getParameter('procedure_id')));

$procedure_mail_templates = new ProcedureMailTemplate;
$this->form = new ProcedureMailTemplateForm($procedure_mail_templates);

Friday, February 11, 2011

Error, Again and Again and Again

Since I'm new with symfony I'm getting lots of errors.

Here are the things I need to do when everything is not working again -- do it from scratch!
  • clear the database
  • dump the new database
  • ./symfony doctrine:migrate ; notice the version returned
    • >> doctrine  Migrating from version 0 to 130
  • update created table migration_version to the version returned (130)
  • ./symfony doctrine:build-model
    • make sure /lib/model/doctrine/base is empty of else it will cause an error
  • ./symfony doctrine:generate-migrations-diff ;
    • should return "Could not generate migration classes from difference"

  • make sure /config/doctrine/schema.yml is updated, specially if planning to add new tables 
  • ./symfony doctrine:generate-migrations-diff (lib/migrations will be genearated)
  • ./symfony doctrine:migrate
    • >> doctrine  Migrating from version 139 to 141
    • >> doctrine  Migration complete

  • run ./symfony doctrine:build-model; ./symfony doctrine:build-sql; ./symfony doctrine:insert-sql
  • ./symfony cache:clear
  • ./symfony doctrine:build-forms;
  • ./symfony generate:module frontend content
  • ./symfony doctrine:build-filters;

Symfony Forms

Forms are needed when we want to insert or modify something in the database. Symfony takes care it for us and we just need to modify few lines to customize it.

./symfony doctrine:build-forms

Wednesday, February 9, 2011

Modules requires a login

A page can be accessed publicly or privately. If the created module needs to be public, we have to do some modifications on the config:

I have added security.yml (/app/frontend/modules/<module-name>config/security.yml) with this content:

  is_secure: true

When someone attempts to access the page, he will receive an alert that he needs to login first.

404 | Not Found | sfError404Exception

I created a new module in symfony:
$ ./symfony generate:module frontend address

and cleared the cache:
$ ./symfony cache:clear

But still I got this error:

Funny! I really can't call it a solution. I was just accessing a wrong URL. Haha!

Instead of:
I went to:

Class not found

Tried to set-up an old web application to a local server. Got an error like "Class no found". It is something to do with auto-loading.

The solution was to run this:

$ php symfony doctrine:build --all-classes --sql

Models don't exist in the source code I have. They said they don't include models in their commits. Why? Because it is auto generated already by symfony.