DateTimeWidget and crudify

I’ve posted the extensions I’m using on my current project. Not posted to the extensions repository yet, they’re still very beta. There’s no documentation or support for them yet, but feel free to have a look at the source at GitHub

The datetime widget encapsulates separate date and time widgets into one, storing the combined value in the model. Time can be disabled by setting the timeFormat parameter to null.

crudify is too difficult to document right now, but the collection of components dynamically generate a crud interface based on metadata and/or methods on the model. Various properties/configurators are available to make certain attributes readonly, appear in admin grids, edit forms, etc.

There are a few conventions I’ve adopted, which make crudify work for me: models must have an id attribute, and a name attribute (or getName() method).

If you want an attribute to be automatically treated as a date or datetime, put a validator in the rules collection, of type ‘type’ and parameter type is ‘date’. If the dateFormat parameter on the rule is longer than 10 characters, it is assumed to be datetime, otherwise simple date.

If an attribute has name ‘password’, it becomes a password element.

If an attribute ends in ‘_at’ it becomes a DsDateTimeWidget element with date and time parts.

If an attribute ends in ‘_on’ it becomes a DsDateTimeWidget element with only a date part.

By default, fields named created_by_id, created_at, updated_by_id, updated_at, deleted_by_id and deleted_at are not displayed when adding a new record. They are displayed when editing an existing record (but not editable).

Relationships between models are automatically taken care of (mostly), by reading the metadata and presenting the appropriate content.

If you want to override an automatically generated form, create a CForm config file in application.forms with the same name as the model. For example, for a user model, create a file protected/forms/User.php with your CForm config. If this does not exist, the form config is generated from the model.

If you want to override the automatically generated view, create a view file in the appropriate place for a controller of the same name as the model. So for example, for a user model, create a file protected/views/user/view.php. If this does not exist, the view is generated from the model.

To control the attributes that appear on the admin view, define a method getAdminAttributes() on your model, which returns an array of attribute names.

To control the attributes that appear on the edit view, define a method getEditAttributes() on your model, which returns an array of attribute names.

If neither one of these is defined, the CrudForm class generates the attributes from the model.

Note the crudify extension uses the DsDateTimeWidget and expects to be hosted at application.extensions.ds.crudify.