Now that everything is set up properly, and you understand the concept of how PHOCOA handles web pages, we will actually create a page to edit our blog.
We will start out by creating a new module, "blog". This module will allow us to search, browse, edit, create, and delete blog posts.
First, cd into the modules subdirectory.
$ cd blog/blog/modules
PHOCOA has a code-generation feature that will quickly build a module providing basic CRUD functionality (Create, Read, Update, Delete) for the selected table. This is done using the phocoa command-line utility:
$ phocoa createSkeletonFromPropel
phing -f /Users/alanpinstein/dev/sandbox/phocoa/phocoa/phing/build.xml -Dusing.phocoa.make=true -Dphocoa.pwd=/Users/alanpinstein/dev/sandbox/blog/blog/modules -Dphocoa.dir=/Users/alanpinstein/dev/sandbox/phocoa/phocoa -Dphocoa.project.name=blog -Dphocoa.project.dir=/Users/alanpinstein/dev/sandbox/blog/blog createSkeletonFromPropel
Buildfile: /Users/alanpinstein/dev/sandbox/phocoa/phocoa/phing/build.xml
phocoa > prepareGeneral:
[echo] PHOCOA framework base dir at: /Users/alanpinstein/dev/sandbox/phocoa/phocoa
phocoa > prepareProject:
[echo] 1
[php] Evaluating PHP expression: $_ENV['_']
[echo] PHOCOA project dir at: /Users/alanpinstein/dev/sandbox/blog/blog
[realpathexpandhome] Resolved /Users/alanpinstein/dev/sandbox/blog/blog/.. to /Users/alanpinstein/dev/sandbox/blog
[echo] PHOCOA project container dir at: /Users/alanpinstein/dev/sandbox/blog
[property] Loading /Users/alanpinstein/dev/sandbox/blog/blog/conf/build.properties
[property] Unable to find property file: /Users/alanpinstein/dev/sandbox/blog/blog/conf/build.properties... skipped
phocoa > createSkeletonFromPropel:
Database Name: [blog]
Table Name: blog
Column name of single column that best describes the table: title
Module Name: [blog]
[php] Evaluating PHP expression: require('/Users/alanpinstein/dev/sandbox/blog/blog/conf/webapp.conf')
[exec] Executing command: /opt/local/bin/php /Users/alanpinstein/dev/sandbox/phocoa/phocoa/framework/createModule.php blog 2>&1
[exec] Writing blog/blog.php
[exec] Done building module blog!
[exec] Executing command: /opt/local/bin/php /Users/alanpinstein/dev/sandbox/phocoa/phocoa/framework/createSkeletonFromPropel.php --phocoaConfFile=/Users/alanpinstein/dev/sandbox/blog/blog/conf/webapp.conf --propelOutputDir=/Users/alanpinstein/dev/sandbox/blog/blog/classes --propelConfFile=/Users/alanpinstein/dev/sandbox/blog/blog/conf/blog-conf.php --databaseName=blog --tableName=blog --columnName=title --pageType=search,edit,detail 2>&1
[exec] Setting up page: search
[exec] Adding shared instance: Blog
[exec] Adding shared instance: 'paginator'
[exec] Saving updated shared.instances
[exec] Adding config for shared instance: Blog
[exec] Adding config for shared instance 'paginator'
[exec] Saving updated shared.config
[exec] Saving updated search.instances
[exec] Saving updated search.config
[exec] Creating search.tpl file.
[exec] Setting up page: edit
[exec] Saving updated shared.instances
[exec] Saving updated shared.config
[exec] Adding instance: blogId
[exec] Adding config for instance: blogId
[exec] Adding instance: postDts
[exec] Adding config for instance: postDts
[exec] Adding instance: title
[exec] Adding config for instance: title
[exec] Adding instance: post
[exec] Adding config for instance: post
[exec] Saving updated edit.instances
[exec] Saving updated edit.config
[exec] Creating edit.tpl file.
[exec] Saving updated confirmDelete.instances
[exec] Saving updated confirmDelete.config
[exec] Creating confirmDelete.tpl file.
[exec] Saving updated deleteSuccess.instances
[exec] Saving updated deleteSuccess.config
[exec] Creating deleteSuccess.tpl file.
[exec] Setting up page: detail
[exec] Saving updated shared.instances
[exec] Saving updated shared.config
[exec] Adding instance: blogId
[exec] Adding config for instance: blogId
[exec] Adding instance: postDts
[exec] Adding config for instance: postDts
[exec] Adding instance: title
[exec] Adding config for instance: title
[exec] Adding instance: post
[exec] Adding config for instance: post
[exec] Saving updated detail.instances
[exec] Saving updated detail.config
[exec] Creating detail.tpl file.
[exec] Suggested module code in suggested_code.php
[exec] Executing command: /opt/local/bin/php /Users/alanpinstein/dev/sandbox/phocoa/phocoa/framework/util/convertModuleToYAML.php blog 2>&1
[exec] Converting shared setup to YAML for module at: 'blog'
[exec] Checking .
[exec] Checking ..
[exec] Checking blog.php
[exec] Checking confirmDelete.config
[exec] Checking confirmDelete.instances
[exec] Checking confirmDelete.tpl
[exec] Converting page: confirmDelete.tpl to YAML
[exec] Checking deleteSuccess.config
[exec] Checking deleteSuccess.instances
[exec] Checking deleteSuccess.tpl
[exec] Converting page: deleteSuccess.tpl to YAML
[exec] Checking detail.config
[exec] Checking detail.instances
[exec] Checking detail.tpl
[exec] Converting page: detail.tpl to YAML
[exec] Checking edit.config
[exec] Checking edit.instances
[exec] Checking edit.tpl
[exec] Converting page: edit.tpl to YAML
[exec] Checking search.config
[exec] Checking search.instances
[exec] Checking search.tpl
[exec] Converting page: search.tpl to YAML
[exec] Checking shared.config
[exec] Checking shared.instances
[exec] Checking shared.yaml
[exec] Checking suggested_code.php
[delete] Deleting 12 files from /Users/alanpinstein/dev/sandbox/blog/blog/modules/blog
[exec] Executing command: mv suggested_code.php blog.php 2>&1
BUILD FINISHED
Total time: 4.4874 seconds
The phocoa createSkeletonFromPropel command automatically creates a new module and code for all of these functions.
![]() | You should not run the code generator more than once for the same module. This may be supported in a future version; right now the effect is untested. |
You can now visit your blog editing module at http://servername/blog.
You will notice that this is a fully-functional blog CRUD module. It is also easily maintainable and extensible.
The next few sections will provide a tour of PHOCOA's core technologies and what they do for you. We'll also make a bunch of modifications along the way to improve the generated code.