Admin Generator for Symfony 1.4 is a powerful tool that creates a fully operational backend application, for administering the site.
The idea behind it, is to create fully operational modules based on module classes, by specifying the model class name in the line command that creates the module:
php symfony doctrine:generate-admin backend Profile
Another important aspect is the generator.yml file which contains all the configuration necessary for the Admin Generator. Also they also provide a default styling made available by typing the following comand on the console:
$ php symfony plugin:publish-assets
This article is not a tutorial about how to implement Admin Generator since Symfony’s tutorial is a very good one, but my aim is to underline only some aspects that aren’t so well documented in the official documentation.
A problem I faced was the need to make conditional object actions, that depend on the state off the object.
The solution was to override the _list_td_actions.php file that is situated in the cache. All the files for the backend are generated every time and are stored in cache. In the new template, I had the object upon which I made the action, and it contained all the data from its table in the database, so it was easy to put a condition concerning the state of the object.The same thing can be done with batch actions.
There were several solutions provided on Symfony’s forums but none of them worked, so the solution I implemented was to copy the needed templates in the backend app, keeping their path the same.
<?php if($profile['is_active'] == 1): ?>
<li>
<?php echo link_to(__('Deactivate', array(), 'messages'),
'profile/ListDeactivate?id='.$profile->getId(), array()); ?>
</li>
<?php endif; ?>
One important thing here is that when changes are being made to the generator.yml, concerning the template, the template in the backend app previously copied is not modified so it has to be copied again.