1. Employee base
|This application is situated in the example1 folder. To run it on your own server you need to create its table and data by executing the SQL in the file 'examples.sql/example1.sql'. To try it out on the phpPeanuts website click here.
Apart from the modifications for creating an application we only added
a hyperlink to skinSubmenu.php in the application folder for
accessing the list of employees. It links to index.php?pntType=Employee.
The domain model of application consist on only one class: . It is situated in in the classes folder. In the class definition you can see Employee extends PntDbObject. We can conclude that instances of Employee are and that they are .
Notice that the class PntDbObject has been included by a special framework method 'includeClass'. It is important to use this method for including classes, otherwise the framework can not correctly retrieve the class name from an object. See 'How to include a class'.
Explanation of the methods:
This is all the information the phpPeanuts framework needs to operate an IndexPage that retrieves Employee peanuts and shows them as rows in a table. If you click on a row you get an EditDetailsPage that contains a form in which you can edit the values of the properties of the Employee that are not readOnly.
- is only there for future extension.
- defines the name of the database table the objects are stored in and retrieved from.
- is the place to define properties. Normally some are defined here, whose values can be set by the user and will be stored in/retrieved from the database. But to keep thinks as simple as possible, we used the method to add fieldProperties for all columns in the database. See how to add field properties for database columns automaticly.
Because addDbFieldProps defines the type and length for each field property, the framework will automatically validate settings done by the user. But if properties are defined manually, one can make more settings to get more complete validation. It will also perform better because less databese queries will be necessary. See for how to define these properties manually.
- We also defined the 'name', whose value will be calculated by its . Values of this property are not available in a field and are not stored in the database.
- defines how a list of employee peanuts should be sorted. With version 1.4.beta1 and up it can be omitted, the objects will then be sorted by the first persistent field property that is not an id property.
is a getter method for the inherited derived property 'label' that is used by the framework as the default way to display an employee peanut to the user. With version 1.4.beta1 and up this method can be omitted. The label will then be the values of the properties according to the result of getLabelSort (or its default). The values will be concatenated separated by spaces. In this example that would have put lastName first, by defining getLabel firstName could be put first.
In the IndexPage you can select some rows with the checkboxes and then press report for a report, or press delete to delete them (on your own web server, on the phpPeanuts website it is blocked).