Make a BREAD Application
Now that you have a model to work with, we will make a basic
application to let you browse, read, edit, add, and delete records.
Make App
At the command line, in the SYSTEM directory,
issue the make-app command using your posts
model. You will see something like the following:
$ ./script/solar make-app Acme_App_Blog --model-name=posts
Making app.
Creating app directory.
Creating app Layout directory.
Creating app Locale directory.
Creating app Public directory.
Creating app View directory.
App class 'Acme_App_Blog' extends 'Acme_Controller_Bread'.
Preparing to write to 'SYSTEM/include/'.
Writing app class.
Writing locale file.
Making public symlinks for 'Acme_App_Blog' ...
Making public directory docroot/public/Acme/App ... done.
Making public symlink for Acme_App_Blog ... done.
... done.
Done.
What happens here is that Solar looks at the class name passed
to make-model, takes the part after the
last underscore, and uses that as the table name. It then
looks up that table in the database and creates files for the
model definition, record class, collection class, column and
index setup information, and locale strings.
Now you can browse to the blog app at http://localhost/index.php/blog.
The table appears to be empty; there are no records.
If you don't like having index.php in the URI,
you will need to point the web server document root to
SYSTEM/docroot and
make sure mod_rewrite is turned on. Then you
can browse to http://localhost/blog.
Alternatively, you can define a virtual host with its own document
root (also pointed at
SYSTEM/docroot and
with mod_rewrite turned on).
Add A Record
Click on the Add link to add a new record.
Where did that "draft/public" select box come from? When we
added the validateInList filter in the model,
the form took that as a hint to preset a list of valid options.
Enter a title for the blog entry and some body text, then click
Save.
If you don't enter a title, the record will not save. instead, you
will see a validation failure message under the form element for
the title.
On a successful add, you will be redirected to the "Edit" page
for the new record.
Now let's see the "Read" page. Click on Read
for that.
That's the default "read" view from the make-app
command. Let's modify that to make it look more blog-like.