Wednesday, June 22, 2011

Setting Page Titles

Setting in action:

Retrieving in template:

Tuesday, June 21, 2011

Query and Call Database

$result = Doctrine::getTable('Shop')->findBySlug($name);

 public function findBySlug($name)
  return Doctrine::getTable('Shop')
     ->where('s.slug = ?', $name)

Tuesday, May 24, 2011

Cross-Application Login

Scenario: You have two apps, frontend and backend. And you want to have only one single login page for frontend and backend applications, either you login from frontend or you login from backend.

Solution: Set both frontend and backend's factories to something like this:
    class: myUser
      timeout:         18000
      logging:         %SF_LOGGING_ENABLED%
      use_flash:       true
      default_culture: %SF_DEFAULT_CULTURE%

    class: sfSessionStorage
      session_name: application_name

Tuesday, May 3, 2011

Using Fixture

If you don't want the task to remove existing data in the database,
use the [--append|COMMENT] option:

[./symfony doctrine:data-load --append|INFO]

Monday, April 25, 2011

Using th native MySQL ENUM type in Symfony 1.4 and Doctrine


To use the native MySQL ENUM type in Symfony and Doctrine you will have to update your "project/config/databases.yml" and add the "use_native_enum" directive under "attributes" i.e: 
         use_native_enum: true
         use_dql_callbacks: true
         default_table_collate: utf8_general_ci
         default_table_charset: utf8

Full Version

    class: sfDoctrineDatabase
      dsn: 'mysql:host=localhost;dbname=mydb_prod'
      username: root
      password: 12345
         use_native_enum: true
         use_dql_callbacks: true
         default_table_collate: utf8_general_ci
         default_table_charset: utf8

Thanks Iman! =)

Thursday, March 24, 2011

Getting Raw Data from Action to Template

Thanks St├ęphane of Google Groups

In a template, you can call $sf_data->getRaw('myActionProperty');
after init it like $this->myActionProperty = array('hey'=>'hoy'); inside an
So you'll get your raw object : unescaped.

Wednesday, March 23, 2011

Clean Everything

php symfony doctrine:build --all-classes --sql
php symfony doctrine:migrate
php symfony plugin:publish-assets
php symfony cc

Creating User Account

php symfony guard:create-user lj regalado

php symfony guard:promote lj

Thursday, March 17, 2011

Symfony admin generator: problems with routing and multiple primary keys

Got the solution from: Symfony admin generator: problems with routing and multiple primary keys

You can easily solve this issue by entering a complex rule using the very same primary keys you defined in your schema.yml. Assuming the “myModule” model has two primary keys “myKey1″ and “myKey2″, you can change your route like the following
column: myKey1/:myKey2
here you go: solved!
Thanks, whoever you are.. ;)

Symfony Admin Gen

./symfony doctrine:generate-admin backend JobeetCategory --module=category

Thursday, March 10, 2011

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.

Wednesday, January 26, 2011

Doctrine:insert-sql InnoDB Error

$ php symfony doctrine:insert-sql

I've got another error after fixing MySQL Driver Error. It says "The 'InnoDB' feature is disabled". I fixed it by editing C:\AppServ\MySQL\my.ini. Commented out line:

# skip-innodb

Restarted my MySQL and re-run the command.

Doctrine:insert-sql MySQL Driver Error

$ php symfony doctrine:insert-sql

I've got an error running this line. It says "Couldn't locate driver name mysql". I gues Mysql is not completely configured yet for symfony.

Enabling the following modules in php.ini file will fix this error:


Don't forget to restart your MySQL.

Running commands from the command prompt

Page 3:

I've got different errors or alert that says my php_mbstring.dll can't be found, or need to be reinstalled or some errors with php4ts.dll. But after a quick research about these extensions, it was suggested to put php_mbstring.dll extension before php_exif.dll in my C:\Windows\php.ini file, like this:


And it worked!

Symfony on Appserv

Page 1 :

Appserv 2.5.10's Apache is not configured yet to serve fake domain/subdomains (or virtual hosts). I chose '' as my fake domain.

The first thing we need to do, is to enable the vhost_alias_module in our Apache configuration file. To do this, we need to open the httpd.conf file located in C:\AppServ\Apache2.2\conf.

Uncomment this line removing sharp (#) :

LoadModule vhost_alias_module module/

Include conf/extra/httpd-vhosts.conf

In conf/extra/httpd-vhosts.conf file:

  DocumentRoot "C:\AppServ\www\symfony\jobeet\web"
  DirectoryIndex index.php
  <Directory "C:\AppServ\www\symfony\jobeet\web">
    AllowOverride All
    Allow from All

  Alias /sf "C:\AppServ\www\symfony\jobeet\lib\vendor\symfony\data\web\sf"
  <Directory "C:\AppServ\www\symfony\jobeet\lib\vendor\symfony\data\web\sf">
    AllowOverride All
    Allow from All

The domain name used in the Apache configuration has to be declared locally. I have added the following line:

in my C:\WINDOWS\system32\drivers\etc\host file.

Then I restarted my Apache server. To do that,
  • Right-click C:\AppServ\Apache2.2\bin\httpd.exe
  • Click "Run as Administrator"
Test in your browser.


Alright! I have decided to create this blog for those who are symfony beginners like me. This may not be useful to all of you but at least I have shared some of the errors I've encountered and the fix I've done.

I'm using:
  • Dell Inspiron 560
  • Pentium(R) Dual-Core CPU E5400 @ 2.70GHz 2.70 GHz
  • Windows 7
  • 2 GB RAM
Has installed:
Has downloaded: