If you are using admin generator in symfony 1.4, i bet you will have the problem to customize admin generator listing to show data from foreign table. It’s common for us to display data from different tables within a listing.
To customize admin generator listing to show foreign tables data, follow the steps below:-
- Let’s say we have 2 tables user_logins and user_profiles tables that store user login and their profile details.
- I’ve a user_login module that generated thru the admin generator
- Now i want to customize my admin generator listing to display some user_profiles data. Let say we only want to display 3 columns in our listing eg: user_id, user_name, user_profile_gender
- To do this, first we need to edit the generator.yml
list: display: [user_id, user_name, _user_profiles]
* if you notice, i put a underscore at the user_profiles field.
- Now create a file name it _user_profiles.php in the module templates directory with the content below:-
<?php echo $user_login->getUserProfile()->getGender(); ?>
* Make sure you declare the correct relationship between the user_login and user_profiles table. else you will get error when you call getUserProfile().
- Now, refresh your user_login module listing and you should see the gender is displayed within the listing.
* there might be a better solution out there, if you found one remember to share with the others!