创建Post视图

来源:互联网 发布:mac 源代码管理工具 编辑:程序博客网 时间:2024/05/14 17:36
现在我们有我们的数据流向我们的模型,我们的应用程序逻辑和流定义为我们的控制器,让我们创建一个视图索引行动上面创建的。
CakePHP的观点只是presentation-flavored碎片,容纳应用程序的布局。对于大多数应用程序,他们是HTML和PHP,但他们最终可能会为XML、CSV、甚至二进制数据。
布局演示代码,裹着一个视图。可以定义多个布局,你可以在它们之间切换,但是现在,我们只使用默认值。
还记得我们在上一节“帖子”变量分配给视图使用set()方法?将数据传递给视图,看起来是这样的:
// print_r($posts) output:Array(    [0] => Array        (            [Post] => Array                (                    [id] => 1                    [title] => The title                    [body] => This is the post body.                    [created] => 2008-02-13 18:34:55                    [modified] =>                )        )    [1] => Array        (            [Post] => Array                (                    [id] => 2                    [title] => A title once again                    [body] => And the post body follows.                    [created] => 2008-02-13 18:34:56                    [modified] =>                )        )    [2] => Array        (            [Post] => Array                (                    [id] => 3                    [title] => Title strikes back                    [body] => This is really exciting! Not.                    [created] => 2008-02-13 18:34:57                    [modified] =>                )        ))
CakePHP的视图文件存储在/ app /视图控制器命名的文件夹内对应。(我们要创建一个文件夹命名为“文章”在这种情况下。)这篇文章格式数据转换成一个漂亮的表,视图代码看起来是这个样子的
// print_r($posts) output:Array(    [0] => Array        (            [Post] => Array                (                    [id] => 1                    [title] => The title                    [body] => This is the post body.                    [created] => 2008-02-13 18:34:55                    [modified] =>                )        )    [1] => Array        (            [Post] => Array                (                    [id] => 2                    [title] => A title once again                    [body] => And the post body follows.                    [created] => 2008-02-13 18:34:56                    [modified] =>                )        )    [2] => Array        (            [Post] => Array                (                    [id] => 3                    [title] => Title strikes back                    [body] => This is really exciting! Not.                    [created] => 2008-02-13 18:34:57                    [modified] =>                )        ))


0 0
原创粉丝点击