| Sign In |
"Alien Mind" by Paul Iannotti, Kevin Hendrickson and John Morgan |
|
|
|
|
generate restful scaffolding with code stylist for win/mac/lin |
|
Posted February 25th, 2007 by brian Code Stylist is a graphical development utility which can generate model, view and controller code for Web-database applications. The program is designed to work with the dbscript open source framework, which combines REST-style Web services with content-negotiation. This tutorial will walk you through generating an edit form for records in an SQL database. step 1to install code stylist on your workstation, browse to codestylist.com and choose your desktop platform. installation is quick and painless, and it can be completely uninstalled just by deleting the application folder. (windows versions include an uninstaller) step 2the codestylist.php file must be placed in your Web server folder. to copy the file, launch the code stylist application and choose the menu item: File > Copy to... pick a destination folder to copy the file to. in the same folder where codestylist.php is installed, create a folder named site.
on linux & mac systems you must set the permissions on the site folder to allow write-access.
step 3click the Setup button in code stylist. set the Base URL to match the location of your codestylist.php file. punch in your database settings and click the Verify Setup button to test your configuration.
step 4if you've gotten this far, you're ready to generate some application code. at the bottom left of the code stylist window, click the + button to add a new page. choose a database table to begin the process.
step 5the mvc generation templates are written in php and can be customized to suit your taste, you will find a range of built-in templates to experiment with. some templates, such as index.html, can render an unlimited number of database fields, while others such as image.jpg are limited to just one or a few fields. the file extensions of the templates are designed to tie into the content-negotiation features of the dbscript framework, representations can be chosen automatically by client preference, or explicitly by adding an extension to the url.
step 6check the boxes for the fields to appear on the new page. drag fields up and down to change their order of appearance.
step 7click on each of the fields to choose what type of form control to use for that field.
step 8choose a name for the new page, in most cases you can accept the default.
step 9now you can see the page that has been generated from the template.
and here is the page controller, which will execute before the page is rendered.
step 10click the Publish button to send the generated files to the site folder. this will forward your browser to the introspection (list of tables) page, from which you can navigate to your generated page.
on your desktop you will find a folder named Untitled with all of the generated files. this folder is monitored by code stylist, and any changes you make to the files can be propagated to your site folder by clicking the Publish button in code stylist.
updating dbscriptnew releases of dbscript are coming out all the time, these instructions will help you update your code stylist installation to use the latest version.
|
|
|
rest web services plus content-negotiation equals dbscript |
|
Posted February 22nd, 2007 by brian dbscript is a new framework for PHP, it features REST-style web services, content-negotiation and a Rails-style template arrangement. step 1visit dbscript.net to download the latest version of dbscript, unzip it into a folder on your Web server, you'll find these files: step 2dbscript comes with a few data models in db/models, these can be deleted but for the Entry model, which enables metadata (eTag/last_modified) about a record in any table. you'll notice that data model names are always singular, and tables and controllers are plural. the Entry model corresponds with a table named entries, the Person model goes with the people table, etc. here is a simple data model for the posts table, it should be saved as db/models/Post.php the framework will perform the CREATE TABLE from the data model information
step 3the following controller for the posts resource includes get, post and _index functions. the _index function is triggered before the partial template _index.xhtml is loaded, and it passes a single named variable, $collection, to the template. we could have a index function as well, which could pass variables to the layout template index.xhtml. templates and controller functions that begin with an underscore are "partials" which means they are intended to be rendered inside a layout template. save this file as db/controllers/posts.php
step 4this layout gets its doctype from dbscript's included templates by calling render_partial, which will look for a template named _doctype.xhtml -- if the template is not found in /views/posts then the template in /views can be used. content_for_layout is a sort of alias for render_partial, it will render a partial for the current $request->action -- so a request to http://host/?posts/new would render the partial _new.xhtml in this space. otherwise the _index.xhtml partial would be rendered. save this as views/posts/index.xhtml
step 5this is the partial template, which loops over each Post in the collection. save it as views/posts/_index.xhtml
step 6an input form for creating new posts, save it as views/posts/_new.xhtml the URL for this form would be http://host/?posts/new
step 7to enter your database settings, open the file db/config.yml -- currently only postgresql and mysql are supported
step 8now you can browse to http://host/?posts/new to submit a new post, BUT first you'll have to change the data model from let_read to let_access to allow new records to be created idbdbscript includes an interactive shell called idb, which is adapted from Jan Kneschke's PHP Shell, here are a few examples:
if save() produces errors, use post->set_value( field, value ) and post->save_changes() |
|
|