Wednesday, June 22, 2011

Setting Page Titles

Setting in action:
$this->getResponse()->setTitle($shopInfo->getName());

Retrieving in template:
$sf_response->getTitle();

Tuesday, June 21, 2011

Query and Call Database

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

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

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:
all:
  user:
    class: myUser
    param:
      timeout:         18000
      logging:         %SF_LOGGING_ENABLED%
      use_flash:       true
      default_culture: %SF_DEFAULT_CULTURE%

  storage:
    class: sfSessionStorage
    param:
      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

from: http://imanpage.com/code/using-th-native-mysql-enum-type-symfony-14-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: 
      attributes:      
         use_native_enum: true
         use_dql_callbacks: true
         default_table_collate: utf8_general_ci
         default_table_charset: utf8

Full Version

all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn: 'mysql:host=localhost;dbname=mydb_prod'
      username: root
      password: 12345
      attributes:                
         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
action.
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 bit2bit.it, whoever you are.. ;)

Symfony Admin Gen

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

Thursday, March 10, 2011

Friday, February 18, 2011

Calling Ajax

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

function getMailTypeText(){
 $.ajax({
        url: $('input#getMailTypeText').val(),
        data: { mail_type_id:  $('select#procedure_mail_template_mail_type_id').val()},
        dataType: 'json',
        success: function(xhr){
   $('div#mail_type_text').html(xhr["text1"]);
        }
    });
}

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(), 
  array(
    'value'=>$this->getObject()->get('procedure_id')
 ));  
}
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;
$procedure_mail_templates->setProcedureId($request->getParameter('procedure_id'));
$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.

http://www.symfony-project.org/forms/1_4/en/11-Doctrine-Integration


./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:

all:
  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:

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

Instead of:
/frontend_dev.php/addres
I went to:
/frontend_dev.php/address/index

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:

extension=php_mysql.dll;
extension=php_pdo;
extension=php_pdo_mysql;

Don't forget to restart your MySQL.

Running commands from the command prompt

Page 3: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/03

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:

;extension=php_dbase.dll
extension=php_mbstring.dll
extension=php_exif.dll
;extension=php_fdf.dll

And it worked!

Symfony on Appserv

Page 1 : http://www.symfony-project.org/jobeet/1_4/Doctrine/en/01

Appserv 2.5.10's Apache is not configured yet to serve fake domain/subdomains (or virtual hosts). I chose 'jobeety.com' 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/mod_vhost_alias.so
and

Include conf/extra/httpd-vhosts.conf

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

<VirtualHost 127.0.0.1:8080>
  DocumentRoot "C:\AppServ\www\symfony\jobeet\web"
  ServerName jobeety.com
  ServerAlias www.jobeety.com
  DirectoryIndex index.php
  <Directory "C:\AppServ\www\symfony\jobeet\web">
    AllowOverride All
    Allow from All
  </Directory>

  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
  </Directory>
</VirtualHost>


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

127.0.0.1 jobeety.com

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 http://jobeety.com in your browser.

Introduction

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: