Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1187325
  • 博文数量: 89
  • 博客积分: 10546
  • 博客等级: 上将
  • 技术积分: 1510
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-16 01:24
文章分类

全部博文(89)

文章存档

2012年(7)

2011年(4)

2010年(5)

2009年(52)

2008年(21)

分类:

2008-10-23 09:38:30

CakePHP内置了命令行工具,可以帮我们生成最基本的CRUD代码,测试等。
cake命令行工具们于CakePHP的核心包的cake/console目录中。
进入app目录,在gnome terminal 中运行../cake/console/cake。


[hantsy@localhost app]$ ../cake/console/cake


Welcome to CakePHP v1.2.0.7692 RC3 Console
---------------------------------------------------------------
Current Paths:
 -app: app
 -working: /home/hantsy/public_html/cakeblog/app
 -root: /home/hantsy/public_html/cakeblog
 -core: /home/hantsy/public_html/cakeblog/

Changing Paths:
your working path should be the same as your application path
to change your path use the '-app' param.
Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp

Available Shells:

 app/vendors/shells/:
         - none

 vendors/shells/:
         - none

 cake/console/libs/:
         testsuite
     i18n
     console
     acl
     api
     bake
     schema

To run a command, type 'cake shell_name [args]'
To get help on a specific command, type 'cake shell_name help'



这是对cake 命令行的一个简单的说明。它会app/vendors/shells,vendors/shells和cake/console/libs 查找可用的Shell。
默认执行cake时要在app下执行,否则你就要指定-app参数到你要操作的程序。
我们这里打算用cake bake 来生成PostsController中的CRUD方法和相应的view文件。

在Gnome Terminal 中运行../cake/console/cake bake。首先创建PostsController,它会覆盖我们事先创建的文件。

[hantsy@localhost app]$ ../cake/console/cake bake


Welcome to CakePHP v1.2.0.7692 RC3 Console
---------------------------------------------------------------
App : app
Path: /home/hantsy/public_html/cakeblog/app
---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[Q]uit
What would you like to Bake? (D/M/V/C/P/Q)
> c


这里我们先创建Controller ,输入C。

---------------------------------------------------------------
Bake Controller
Path: /home/hantsy/public_html/cakeblog/app/controllers/
---------------------------------------------------------------
Possible Controllers based on your current database:
1. Posts
Enter a number from the list above, type in the name of another controller, or 'q' to exit 
[q] > 1


CakePHP会查找根据数据库查找可以创建的Controller,输入选项前的编号1,创建PostsController。

---------------------------------------------------------------
Baking PostsController
---------------------------------------------------------------
Would you like to build your controller interactively?
Warning: Choosing no will overwrite the PostsController. (y/n)
[y] > y


开始创建PostsController,由于此文件已经,cake bake 会提示是否要覆盖。选择y,进行覆盖。


Would you like to use scaffolding? (y/n)
[n] > n


是否使用scaffold ,前面已经演示过了,这里不再使用。

Would you like to include some basic class methods (index(), add(), view(), edit())? (y/n)
[n] > y


是否生成基本的方法,选择y生成。

Would you like to create the methods for admin routing? (y/n)
[n] > n


是否添加admin routing规则,先不添加。

Would you like this controller to use other helpers besides HtmlHelper and FormHelper? (y/n)
[n] > n


使用基本的Html, From 两个helper,暂不需要其它Helper。

Would you like this controller to use any components? (y/n)
[n] > n


是否使用Components,选择n,不使用。

Would you like to use Sessions? (y/n)
[y] > n


先不使用Session。

---------------------------------------------------------------
The following controller will be created:
---------------------------------------------------------------
Controller Name:  Posts
---------------------------------------------------------------
Look okay? (y/n)
[y] > y


确定要生成的PostsController。

Creating file /home/hantsy/public_html/cakeblog/app/controllers/posts_controller.php
File exists, overwrite? /home/hantsy/public_html/cakeblog/app/controllers/posts_controller.php (y/n/q)
[n] > y


确认要覆盖已经有文件posts_controller.php。

Wrote /home/hantsy/public_html/cakeblog/app/controllers/posts_controller.php
Cake test suite not installed.  Do you want to bake unit test files anyway? (y/n)
[y] > n


是否生成测试,不生成测试。

趁热打铁,继续生成相应的view 文件。

---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[Q]uit
What would you like to Bake? (D/M/V/C/P/Q)
> v


输入v,确定生成View。

---------------------------------------------------------------
Bake View
Path: /home/hantsy/public_html/cakeblog/app/views/
---------------------------------------------------------------
Possible Controllers based on your current database:
1. Posts
Enter a number from the list above, type in the name of another controller, or 'q' to exit 
[q] > 1


选择对应的Controller。

Would you like to create some scaffolded views (index, add, view, edit) for this controller?
NOTE: Before doing so, you'll need to create your controller and model classes (including associated models). (y/n)
[n] > y


生成几个最基本的view 文件。

Would you like to create the views for admin routing? (y/n)
[y] > n


不生成admin 的view 文件。

Creating file /home/hantsy/public_html/cakeblog/app/views/posts/index.ctp
File exists, overwrite? /home/hantsy/public_html/cakeblog/app/views/posts/index.ctp (y/n/q)
[n] > y


覆盖已经存在的index.ctp文件。

Wrote /home/hantsy/public_html/cakeblog/app/views/posts/index.ctp

Creating file /home/hantsy/public_html/cakeblog/app/views/posts/view.ctp
Wrote /home/hantsy/public_html/cakeblog/app/views/posts/view.ctp

Creating file /home/hantsy/public_html/cakeblog/app/views/posts/add.ctp
Wrote /home/hantsy/public_html/cakeblog/app/views/posts/add.ctp

Creating file /home/hantsy/public_html/cakeblog/app/views/posts/edit.ctp
Wrote /home/hantsy/public_html/cakeblog/app/views/posts/edit.ctp
---------------------------------------------------------------

View Scaffolding Complete.

---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[Q]uit
What would you like to Bake? (D/M/V/C/P/Q)
>



OK, 现在我们利用cake bake生成相应了PostsController和View文件。
大功告成,通过浏览器打开就可以看到效果,和之前使用scaffold 看到差不多,不过这次运行的是真实的代码。
从运行的画面,可以看到cake bake 还可以生成数据库配置文件,创建项目,生成Model等。在以后的开发中,我们可以自己慢慢体会。
阅读(5837) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

aizai73932008-11-16 16:59:39

进入app目录,在gnome terminal 中运行../cake/console/cake。 请问这句话具体的怎么操作呀。