Phalcon 開発者ツール ======================= These tools are a collection of useful scripts to generate skeleton code. Core components of your application can be generated with a simple command, allowing you to easily develop applications using Phalcon. .. highlights:: If you prefer to use the web version instead of the console, this `blog post`_ offers more information. ダウンロード ------------ You can download or clone a cross platform package containing the developer tools from Github_. インストール ^^^^^^^^^^^^ These are detailed instructions on how to install the developer tools on different platforms: .. toctree:: :maxdepth: 1 wintools mactools linuxtools 利用可能なコマンドの取得 -------------------------- You can get a list of available commands in Phalcon tools by typing: :code:`phalcon commands` .. code-block:: sh $ phalcon commands Phalcon DevTools (3.0.0) Available commands: 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) プロジェクトスケルトンの生成 ----------------------------- You can use Phalcon tools to generate pre-defined project skeletons for your applications with Phalcon framework. By default the project skeleton generator will use mod_rewrite for Apache. Type the following command on your web server document root: .. code-block:: sh $ pwd /Applications/MAMP/htdocs $ phalcon create-project store The above recommended project structure was generated: .. figure:: ../_static/img/tools-2.png :align: center You could add the parameter *--help* to get help on the usage of a certain script: .. code-block:: sh $ phalcon project --help Phalcon DevTools (3.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 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] --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 Accessing the project from the web server will show you: .. figure:: ../_static/img/tools-6.png :align: center コントローラの生成 ---------------------- The command "create-controller" generates controller skeleton structures. It's important to invoke this command inside a directory that already has a Phalcon project. .. code-block:: sh $ phalcon create-controller --name test The following code is generated by the script: .. code-block:: php id = $id; } /** * Method to set the value of field typesId * * @param integer $typesId */ public function setTypesId($typesId) { $this->typesId = $typesId; } // ... /** * Returns the value of field status * * @return string */ public function getStatus() { return $this->status; } } A nice feature of the model generator is that it keeps changes made by the developer between code generations. This allows the addition or removal of fields and properties, without worrying about losing changes made to the model itself. The following screencast shows you how it works: .. raw:: html
CRUDのScaffolding ----------------- Scaffolding is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job. Once the code is generated, it will have to be customized to meet your needs. Many developers avoid scaffolding entirely, opting to write all or most of their source code from scratch. The generated code can serve as a guide to better understand of how the framework works or develop prototypes. The code below shows a scaffold based on the table "products": .. code-block:: sh $ phalcon scaffold --table-name products The scaffold generator will build several files in your application, along with some folders. Here's a quick overview of what will be generated: +----------------------------------------+--------------------------------+ | File | Purpose | +========================================+================================+ | app/controllers/ProductsController.php | The Products controller | +----------------------------------------+--------------------------------+ | app/models/Products.php | The Products model | +----------------------------------------+--------------------------------+ | app/views/layout/products.phtml | Controller layout for Products | +----------------------------------------+--------------------------------+ | app/views/products/new.phtml | View for the action "new" | +----------------------------------------+--------------------------------+ | app/views/products/edit.phtml | View for the action "edit" | +----------------------------------------+--------------------------------+ | app/views/products/search.phtml | View for the action "search" | +----------------------------------------+--------------------------------+ When browsing the recently generated controller, you will see a search form and a link to create a new Product: .. figure:: ../_static/img/tools-10.png :align: center The "create page" allows you to create products applying validations on the Products model. Phalcon will automatically validate not null fields producing warnings if any of them is required. .. figure:: ../_static/img/tools-11.png :align: center After performing a search, a pager component is available to show paged results. Use the "Edit" or "Delete" links in front of each result to perform such actions. .. figure:: ../_static/img/tools-12.png :align: center ツールへのWEBインターフェース ----------------------------- Also, if you prefer, it's possible to use Phalcon Developer Tools from a web interface. Check out the following screencast to figure out how it works: .. raw:: html
ツールとPhpStorm IDEとの統合 ----------------------------------- The screencast below shows how to integrate developer tools with the `PhpStorm IDE`_. The configuration steps could be easily adapted to other IDEs for PHP. .. raw:: html
まとめ ---------- Phalcon Developer Tools provides an easy way to generate code for your application, reducing development time and potential coding errors. .. _blog post: https://blog.phalconphp.com/post/dont-like-command-line-and-consoles-no-problem .. _Github: https://github.com/phalcon/phalcon-devtools .. _Bootstrap: http://twitter.github.com/bootstrap/ .. _PhpStorm IDE: http://www.jetbrains.com/phpstorm/