脚手架通常是指一种代码生成,我们将其指向Web应用程序数据库,从而创建基本的CRUD(创建,读取,更新,删除)应用程序.
在设计CRUD应用程序之前,根据应用程序的需要设计数据库表非常重要.
步骤1 : 创建一个包含所有crud操作的脚手架应用程序.
Command: phalcon scaffold
脚手架一旦执行了Phalcon的生成器将创建下表中描述的文件和文件夹.
第2步 : 创建索引页面(phtml和伏特的组合).
要包含在用户文件夹中的index.phtml中的代码.
Blog Tutorial getContent() ?>
默认文件 index.volt 将包含以下代码.
getContent() ?>Welcome!
Welcome to the blog collection of Phalcon
上述代码的成功执行会产生以下输出.
第3步 : 使用相应型号进行更改.
Users.php
hasMany("id", "Posts", "users_id"); } }
名为'initialize'的函数有助于实现id和users_id之间的关系帖子表,这意味着每个唯一用户在表格中都有很多帖子.
Posts.php
belongsTo("users_id", "Users", "id"); $this->belongsTo("categories_id", "Categories", "id"); } }
函数'initialize'包括提及外键和主键的关系约束与表格的关系.
users_id 是指"用户"表格中的ID.
categories_id 引用"类别"表中的id.
Categories.php
hasMany("id", "Posts", "categories_id"); } }
与用户模型类似,'initialize'函数指定它包含许多给定帖子的 categories_id .
设计登录第页
创建视图
以下是Blog-tutorial-master项目的完整结构.
用户成功登录后显示主页的关联视图是 "index.phtml".
Blog Tutorial getContent() ?>