|
NAMECatalyst::Enzyme::CRUD::Model - CRUD Model ComponentSYNOPSISDESCRIPTIONCRUD Model Component.This is how to configure your model classes' meta data. ENZYME MODEL CONFIGURATION:Some things are Enzyme related configurations. These go in the:__PACKAGE__->config( crud => {} ) hash ref. monikerHuman readable name for this model.E.g. "Shop Location". Default: MyApp::Model::CDBI::ShopLocation becomes "Shop Location". column_monikersColumn monikers. Hash ref with (key: column name: value: moniker).Default: based on the column name (id_% and %id removed, the capitalized). Override specific column names like this: column_monikers => { __PACKAGE__->default_column_monikers, url => "URL" }, data_form_validatorValidation rules for the data fields.Default: no validation, all columns are optional. Note that you need to provide the entire config hashref that Data::FormValidator expects. rows_per_pageNumber of rows per page when using a pager (which will happen unless paging is disabled by setting this value is 0).Default: 20 CDBI CONFIGURATIONStringified columnLet's say your Model class Book has a Foreign Key (FK) genre_id to the Genre Model class.In the list of Books, the Genre will just be displayed with this identifier, whereas you really would like it to display the Genre name. In the Genre model class, define the column group Stringify, like this: __PACKAGE__->columns(Stringify => qw/ name /); This magic is performed by Class::DBI and Class::DBI::AsForm's to_field method. When objects are displayed in a "list", the text in the Stringify column will become a link to "view" the object. Fields to displayThe following set of columns can be defined for various uses in the templates. The column names both define which columns to display, and in which order.__PACKAGE__->columns(view_columns => qw/ COLUMNS /); __PACKAGE__->columns(edit_columns => qw/ COLUMNS /); __PACKAGE__->columns(list_columns => qw/ COLUMNS /); The default is all columns except primary keys. These are pre-entered by the Model helper so it's easy for you to remove or change the order. If you like it the way it is, just delete the lines altogether. EXAMPLEuse Data::FormValidator::Constraints qw(:regexp_common); __PACKAGE__->columns(Stringify => qw/ url /); __PACKAGE__->columns(list_columns=> qw/ name email url /); __PACKAGE__->columns(view_columns=> qw/ name email url phone /); __PACKAGE__->config( crud => { moniker => "URL", rows_per_page => 20, data_form_validator => { optional => [ __PACKAGE__->columns ], required => [ "url" ], constraint_methods => { url => FV_URI(), }, msgs => { format => '%s', constraints => { FV_URI => "Not a URL", }, }, }, }, ); CLASS METHODSdefault_column_monikers()Return hash ref with the default column monikers (display names) for all columns.You can use this to setup a Model's crud config like this: __PACKAGE__->config( crud => { column_monikers => { __PACKAGE__->default_column_monikers, url_id => "URL" }; }, ); default_column_moniker($column)Return default name for $column.Remove _id$ and ^id_. Exemple: author_name_id --> Author Name list_columns()Return array with the column names suitable for a list of the objects in this Model.Configure this with: __PACKAGE__->columns(list_columns => qw/ column names /); Default: the default_columns. view_columns()Return array with the column names suitable for viewing an object in this Model.Configure this with: __PACKAGE__->columns(view_columns => qw/ column names /); Default: the default_columns. edit_columns()Return array with the column names suitable for editing an object in this Model.Configure this with: __PACKAGE__->columns(edit_columns => qw/ column names /); Default: edit_columns (if specified), otherwise the default_columns. named_columns($group_name)Return array with the column names identified by __PACKAGE__->columns($group_name).Configure this with: __PACKAGE__->columns($group_name => qw/ column names /); default_columns()Return array with the default column names suitable for an object in this Model.This is all column names, except PK columns. namespace_of_column_has_a($c, $column)If $column has a has_a relationship to another table, return the Model's Controller's namespace (or the first if there are many).Return "" if there are no related tables. AUTHORJohan Lindstrom <johanl ÄT cpan.org>LICENSEThis library is free software . You can redistribute it and/or modify it under the same terms as perl itself.POD ERRORSHey! The above document had some coding errors, which are explained below:
Visit the GSP FreeBSD Man Page Interface. |