Package Data | |
---|---|
Maintainer Username: | bryannielsen |
Maintainer Contact: | max@packettide.com (Max Walker) |
Package Create Date: | 2013-10-24 |
Package Last Update: | 2014-02-05 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-15 15:18:21 |
Package Statistics | |
---|---|
Total Downloads: | 142 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 7 |
Total Watchers: | 4 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Sire allows you to generate models, views, controller, and migrations based on a YAML description file. This makes for repeatedable, tweakable generation. It generates views that utilize Bootstrap 3.
Add new long_named_thing
buttonsAdd "packettide/sire": "@dev"
to the require block of your composer.json
Do a composer update
Add 'Packettide\Sire\SireServiceProvider',
to the end of your app config providers array
Setup a simple YAML file representing your model:
_name: thing
_makes:
- model
- view
- controller
- migration
- route
_viewTheme: bs3
_codeTheme: default
title:
sqlType: string
fieldType: Text
label: Title
validation:
- required
The _name
field tells Sire what the name of the things (views, controller, model, table and routes) you are generating is
The _makes
field tells Sire what to generate for this model. Current options are
model
view
controller
migration
route
seed
The _viewTheme
field tells Sire what the visual look of the app should be. For right now the only options are:
bs3
, which is a Bootstrap 3 powered looknaked
which just generates bare information that you should wrap your own markup around.foundation5
, based on the new version of Zurb Foundation. (Note: This is on the experimental side and may be a little broken in places.)The _codeTheme
doesn't do anything for now but it is there for fowards compatibility
In addition to these special paramters there are also the members of the model. The title
field is a parameter that will appear on the resulting model.
sqlType
which tells the migration generator what format the column should be, see here for more info about the types availible.fieldType
field describes how the generated forms will interact with the parameter.label
is simply the label.validation
field is a list of the rules that the parameter should obey. That small amount of YAML is enough to get you started with Sire.image:
label: An Image
sqlType: string
fieldType: File
fieldTypeOptions:
directory: "/uploads/images"
Here we have a file field. File fields in Bree need to know what directory you want the upload to go to. In Sire we specify that as a fieldTypeOptions
. We set a fieldTypeOption
named directory
and give it a value of "/uploads/images"
. The same works for other options as well.
other:
label: Other Thing
fieldType: Cell
relationshipType: hasMany
relatedModel: Other
We give this field a fieldType of Cell, since it will represent a hasMany by giving you the option to create new instances of the Other model and attaching them to this model. We have to give it:
relationshipType
which tells Sire that this is a hasMany relationshiprelatedModel
with tells Sire what class is going to be related on this relationshipmore:
label: More Things
fieldType: Relate
fieldTypeOptions:
select: true
title: title
relationshipType: belongsTo
relatedModel: More
We are going to give this field a fieldType of Relate. A belongsTo will mean that the migration for this model will have a more_id
with the type integer. We this field:
relationshipType
which tells Sire that it is a belongsTorelatedModel
which tells Sire to relate it to the more classfieldTypeOptions
telling Sire that we want this to be select relate rather than a radio button and we want to label each option with the title from that model.The _seeds
special field is used to create a seeder.
_seeds:
-
title: ' "Thing One" '
new: ' false '
-
title: ' "Thing Two" '
new: ' true '
This will create two intances of our Thing
model with different titles. The most important thing to not here is that we cannot use bare strings. In order for Sire to understand your seeds you need wrap them in '
, additionally you will want to wrap the words Thing One and Thing Two in "
since these are strings. This is slightly confusing but required due to the way yaml works. You can see that with the boolean field new, we do not wrap it in "
, since it is not a string.
Lastly we need to tell Sire to make a seed, like so:
_makes:
- model
- view
- controller
- migration
- route
- seed