脚手架教程
最后更新于:2022-04-02 02:23:09
[TOC]
## 帮助
## 初始化项目 ``` phalcon create-project store ``` ## 控制器
### 创建控制器 ``` $ phalcon create-controller --name test ``` 使用 ```user.php
```
add(
'email',
new EmailValidator(
[
'model' => $this,
'message' => 'Please enter a correct email address',
]
)
);
return $this->validate($validator);
}
/**
* Initialize method for model.
*/
public function initialize()
{
$this->setSchema("test");
$this->setSource("users");
}
/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return Users[]|Users|\Phalcon\Mvc\Model\ResultSetInterface
*/
public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInterface
{
return parent::find($parameters);
}
/**
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return Users|\Phalcon\Mvc\Model\ResultInterface
*/
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}
}
```
## CURD `$ phalcon scaffold --table-name users` | File | 目的 | | --- | --- | | `app/controllers/UsersController.php` | 产品控制器 | | `app/models/Users.php` | Products 模型 | | `app/views/layout/users.phtml` | Controller layout for Users | | `app/views/products/search.phtml` | View for the action`search` | | `app/views/products/new.phtml` | View for the action`new` | | `app/views/products/edit.phtml` | View for the action`edit` |
';
phalcon
``` $ phalcon Phalcon DevTools (4.0.0) Available commands: info (alias of: i) commands (alias of: list, enumerate) controller (alias of: create-controller) module (alias of: create-module) model (alias of: create-model) all-models (alias of: create-all-models) project (alias of: create-project) scaffold (alias of: create-scaffold) migration (alias of: create-migration) webtools (alias of: create-webtools) serve (alias of: server) console (alias of: shell, psysh) ```## 初始化项目 ``` phalcon create-project store ``` ## 控制器
main.go
``` $ phalcon project --help Phalcon DevTools (4.0.0) Help: Creates a project Usage: project [name] [type] [directory] [enable-webtools] Arguments: help Shows this help text Example phalcon project store simple Options: --name=s Name of the new project --enable-webtools Determines if webtools should be enabled [optional] --directory=s Base path on which project will be created [optional] --type=s Type of the application to be generated (cli, micro, simple, modules) --template-path=s Specify a template path [optional] --template-engine=s Define the template engine, default phtml (phtml, volt) [optional] --use-config-ini Use a ini file as configuration file [optional] --trace Shows the trace of the framework in case of exception [optional] --help Shows this help [optional] ```### 创建控制器 ``` $ phalcon create-controller --name test ``` 使用 ```
## CURD `$ phalcon scaffold --table-name users` | File | 目的 | | --- | --- | | `app/controllers/UsersController.php` | 产品控制器 | | `app/models/Users.php` | Products 模型 | | `app/views/layout/users.phtml` | Controller layout for Users | | `app/views/products/search.phtml` | View for the action`search` | | `app/views/products/new.phtml` | View for the action`new` | | `app/views/products/edit.phtml` | View for the action`edit` |