Code snippets for symfony 1.x


Snippets by user Vincent Texier

propel behavior to extend classes with separate tables

I needed to have many subclasses inherited from a main class.

To do that with propel, you need to have all your classes in one big table. I wanted to have separate tables.

Then I discovered the propel behaviors and it does that very well !

Let's see an example with a master class "element" and a subclass "subElement" :

by Vincent Texier on 2007-08-13, tagged behavior  inheritance  model  propel 

Display Primary Key in Admin Generator Edit Form

By default, we can't display primary keys in the admin generator edit view.

But I wanted to do just that.

Here is an example for the module/table "article", and the primary key column "id" :

Beware of the tricky spelling of the partial name in the generator.yml file if, like me, you like underscores...

by Vincent Texier on 2007-08-01, tagged admin  form  generator 
(1 comment)

Ajax request rejected by session timeout

This snippet is usefull to handle a session timeout in an ajax request.

It is very bad to have the login page filling the update div zone...

The idea came from a post in the forum (thanks a lot RoVeRT !)

The method is :

For that purpose, we will add a little code in the ajax helper and in the login action.

1 - We handle the 401 error code in the ajax helper and enable javascript execution for the popup :

401 => "if ( confirm('Your not logged anymore... Ok to go to the login page.')) {document.location='/';}",

2 - We add this code at the beginning of the login action :

// if the request is an ajax request...
if ($this->getRequest()->isXmlHttpRequest()) {
// response to the ajax request : code http 401 (access unauthorized)

Thanks for the comments !

by Vincent Texier on 2006-10-25, tagged ajax  session