Code snippets for symfony 1.x

Navigation

Snippets by user Kota Sakoda

How to use sfMail to encode body of Japanese Email.

How to use sfMail to encode Body of Japanese Email.

The Japanese Email usually use ISO-2022-JP. But, I want to use UTF-8 of any Email template files. For example...

I create PROJECT_DIR/lib/myMail.class.php

myMail.class.php

<?php
 
class myMail extends sfMail
{
  public function setBody ($body)
  {
    parent::setBody(mb_convert_encoding($body, "JIS", "UTF-8"));
  }
}
 
?>

OK, Use this class from your Action.

actions.class.php

  public function executeSendmail()
  {
    $mail = new myMail();
    ....
  }
by Kota Sakoda on 2007-02-13, tagged email  encode  iso2022jp  japanese  sfmail  utf8 

How to check radiobutton after post.

The boolean is set to The third argument.

<?php echo radiobutton_tag('status', 'value1', true) ?>
<?php echo radiobutton_tag('status', 'value2', false) ?>

It write like this.

<?php echo radiobutton_tag("status", "value1", $sf_params->get("status") == 'value1'); ?>
<?php echo radiobutton_tag("status", "value2", $sf_params->get("status") == 'value2'); ?>
by Kota Sakoda on 2006-08-30, tagged forms  view 
(3 comments)

Using multiple databases from Propel

if you using multiple database from Propel, It can be solve by writing two or more schema files.

PROJECT_DIR/config/databases.yml

all:
  database1:
    class:   sfPropelDatabase
    param:
      dsn:   pgsql://foo:bar@hostname/database1

  database2:
    class:   sfPropelDatabase
    param:
      dsn:   mysql://foo:bar@hostname/database2

PROJECT_DIR/config/database1.schema.xml

<?xml version="1.0" encoding="UTF-8"?>
<database name="database1" defaultIdMethod="native" noxsd="true">
  <table name="foo" phpName="Foo">
    ....
  </table>
</database>

PROJECT_DIR/config/database2.schema.xml

<?xml version="1.0" encoding="UTF-8"?>
<database name="database2" defaultIdMethod="native" noxsd="true">
  <table name="bar" phpName="Bar">
    ....
  </table>
</database>

Last, build model command.

$ symfony propel-build-model

Build complete.

Example, getting multiple databases connection handler.

$database1_connection_handler = Propel::getConnection(FooPeer::DATABASE_NAME);
$database2_connection_handler = Propel::getConnection(BarPeer::DATABASE_NAME);
by Kota Sakoda on 2006-08-30, tagged database  model  propel 
(1 comment)