![]() |
|
Snippets |
|
Let's take an example. You want to have the user culture in front of each of your URL.
So, your routing configuration look like something like that:
page: url: /:culture/:page params: ... article: url: /:culture/:year/:month/:day/:slug params: ... ...
This is the easy part. But now, every time you call url_for() or link_to() you have to pass the culture parameter.
For such situations, there is a better way. The routing has a special configuration parameter named sf_routing_defaults that you can set with default values:
sfConfig::set('sf_routing_defaults', array('culture' => 'en'));
And now, the culture parameter will automatically added to the parameters that you pass to the url_for() or link_to() helpers.
Sometimes, you want to create your own symfony PEAR package from the current trunk or from a particular branch. Or perhaps you did a checkout of the trunk and did some changes.
It's very simple to create your own PEAR package from such a directory:
pake release 0.8.1 stable
and pake will create a symfony PEAR package with the version 0.8.1.
You will now be able to install this with the pear command line tool:
pear install symfony-0.8.1.tgz
Sometimes, you want to do something just before or just after saving or deleting an object in the admin generator. To do that, you can override the saveObject() and/or deleteObject() method in your actions.class.php file:
protected function saveCustomer($customer) { // pre save hook $customer->setManagerId($this->getUser()->getManagerId()); // call the parent save() method parent::saveCustomer($customer); // post save hook }
You can also bypass the parent method if you want.
protected function deleteCustomer($customer) { $customer->isDeleted(true); // save the customer object $this->saveCustomer($customer); // bypass the deletion by not calling the parent method }
If you want to restrict the objects displayed in the admin generator, you can add a permanent criteria by overriding the addFiltersCriteria() method:
protected function addFiltersCriteria(&$c) { $c->add(CustomerPeer::DELETED, false); }
By default, symfony stores user sessions in files.
You can store them in your database by changing your apps/APPNAME/config/factories.yml configuration file:
all:
storage:
class: sfMySQLSessionStorage
param:
database: propel
db_table: SESSION_TABLE_NAME
There are several available session storage classes:
The API documentation lists all available configuration parameters.
To use database connections defined in the databases.yml configuration file, you can use the following snippet:
// initialize database manager $databaseManager = new sfDatabaseManager(); $databaseManager->initialize();
$con = Propel::getConnection(); try { $con->begin(); // do something $con->commit(); } catch (Exception $e) { $con->rollback(); throw $e; }
To enable InnoDB support in Propel, you can add this line at the end of your config/propel.ini configuration file:
propel.mysql.tableType = InnoDB