General aims:
1. Create the backend interface for administrators.
2. Start by mapping out the main tables, creating for each an interface which would allows us to see,edit,delete the records.
3. Map out
the relationships between tables and see how we can use a smaller number of interfaces to effect more tables at once.
1. Create the interface (from command line)
Create the backend application
symfony init-app backend
Create the backend admin interface for each table we need :
symfony propel-init-admin backend street Street
symfony propel-init-admin backend building Building
symfony propel-init-admin backend occupant Occupant
symfony propel-init-admin backend occupancy Occupancy
…
go to one of them to check everything is fine: http://localhost:8020/backend_dev.php/street
2. Map out the tables
goal1: add actions to each record
show the list of streets and for each street add the capability to edit the street details with an icon (_edit), apart from clicking on the street id.
Modify the button to create a new record ( _create)
Open generator.yml in the config folder of your street module (backend/street/config):
generator:
class: sfPropelAdminGenerator
param:
model_class: Street
theme: default
fields:
idstreet: {name: Street id}
streetname:{name: Street name}
list:
title: Adopted streets
object_actions:
_edit: -
actions:
_create: {name: add a new street}
goal2: Modify the column headers
Replace the buildings table column headers which currently display idbuilding and buildingnum, with something more readable, i.e. Building ID and Civic Number. To do so, open the generator.yml for the building module and add the following:
fields:
idbuilding:{name: Building ID}
buildingnum:{name: Civic number}
goal3: modify how a value is displayed inside a column
The buildings table shows the id of the street each building belongs to. We would like to have the name of the street displayed instead. To do so, we need to create a partial (a piece of layout) and call this in the generator instead of the id.
Define a default method on the Street object (__toString) which returns the street name, in class Street.php.
public function __toString(){
return $this->getStreetname();
}
Define the partial: create _street.php in the templates folder of the building module. Call the toString method of the street object, as previously defined (to do so, is getClassname).
<?php
echo $building->getStreet();
?>
Call the partial: open the generator.yml for building module and insert a display action where instead of using idstreet (which calls the value of that column) we call the partial (_street) we have defined.
list:
title: list of buildings
display:[idbuilding, buildingnum, _street, buildingname, latitude, longitude]
filters: [idstreet]
goal4: filter the table records
In the generator, under display add the filter according to the street, which will display only those buildings registered for that street.
display:....
filters: [idstreet]
3. Map out the relationships
goal 1: for each street in the streets table view, add a link which redirects to see all the buildings related to that street.
Create a custom object action (to be placed under _edit), with a tag name (which will appear on rollover), the name of the action to be called (which will be defined in the actions.class.php of street module (1)) and an icon (this is one of the collection provided by the system). This is the code:
list:
object_actions:
_edit: -
all_buildings:{name: see all buildings for this street, action: Buildings, icon: /sf/sf_admin/images/filter.png }
In streetActions class (action.class.php in the street module), define an action Buildings (so it has to be executeBuildings), which gets the id of the current record and redirects to the list of buildings using that record as a filter.
public function executeBuildings(){
$this->redirect('building/list?filter=filter&filters[idstreet]='.$this->getRequestParameter('idstreet'));
}
That’s what you end up with:

Problems solved
symfony does not show foreign keys
this is because in your db model, you the foreign key is also primary. Define it solely as a foreign key, recreate schema xml and the model.