V?kuró is another sample application you can use to learn more about Phalcon. V?kuró is a small website that shows how to implement a security features and management of users and permissions. You can clone its code from Github.
Project Structure
Once you clone the project in your document root you’ll see the following structure:
~~~
vokuro/
app/
config/
controllers/
forms/
library/
models/
views/
cache/
public/
css/
img/
schemas/
~~~
This project follows a quite similar structure to INVO. Once you open the application in your browser http://localhost/vokuro you’ll see something like this:

The application is divided into two parts, a frontend, where visitors can sign up the service and a backend where administrative users can manage registered users. Both frontend and backend are combined in a single module.
Load Classes and Dependencies
This project uses Phalcon\Loader to load controllers, models, forms, etc. within the project and composer to load the project’s dependencies. So, the first thing you have to do before execute V?kuró is install its dependencies via composer. Assuming you have it correctly installed, type the following command in the console:
~~~
cd vokuro
composer install
~~~
V?kuró sends emails to confirm the sign up of registered users using Swift, the composer.json looks like:
~~~
{
"require" : {
"php" : ">=5.5.0",
"ext-phalcon" : ">=3.0.0",
"swiftmailer/swiftmailer" : "^5.4",
"amazonwebservices/aws-sdk-for-php" : "~1.0"
}
}
~~~
Now, there is a file called app/config/loader.php where all the auto-loading stuff is set up. At the end of this file you can see that the composer autoloader is included enabling the application to autoload any of the classes in the downloaded dependencies:
~~~
<?php
// ...
// Use composer autoloader to load vendor classes
require_once BASE_PATH . "/vendor/autoload.php";
~~~
Moreover, V?kuró, unlike the INVO, utilizes namespaces for controllers and models which is the recommended practice to structure a project. This way the autoloader looks slightly different than the one we saw before (app/config/loader.php):
~~~
<?php
use Phalcon\Loader;
$loader = new Loader();
$loader->registerNamespaces(
[
"Vokuro\\Models" => $config->application->modelsDir,
"Vokuro\\Controllers" => $config->application->controllersDir,
"Vokuro\\Forms" => $config->application->formsDir,
"Vokuro" => $config->application->libraryDir,
]
);
$loader->register();
// ...
~~~
Instead of using `registerDirectories()`, we use `registerNamespaces()`. Every namespace points to a directory defined in the configuration file (app/config/config.php). For instance the namespace Vokuro\Controllers points to app/controllers so all the classes required by the application within this namespace requires it in its definition:
~~~
<?php
namespace Vokuro\Controllers;
class AboutController extends ControllerBase
{
// ...
}
~~~
Sign Up
First, let’s check how users are registered in V?kuró. When a user clicks the “Create an Account” button, the controller SessionController is invoked and the action “signup” is executed:
~~~
<?php
namespace Vokuro\Controllers;
use Vokuro\Forms\SignUpForm;
class RegisterController extends ControllerBase
{
public function signupAction()
{
$form = new SignUpForm();
// ...
$this->view->form = $form;
}
}
~~~
This action simply pass a form instance of SignUpForm to the view, which itself is rendered to allow the user enter the login details:
~~~
{{ form("class": "form-search") }}
<h2>
Sign Up
</h2>
<p>{{ form.label("name") }}</p>
<p>
{{ form.render("name") }}
{{ form.messages("name") }}
</p>
<p>{{ form.label("email") }}</p>
<p>
{{ form.render("email") }}
{{ form.messages("email") }}
</p>
<p>{{ form.label("password") }}</p>
<p>
{{ form.render("password") }}
{{ form.messages("password") }}
</p>
<p>{{ form.label("confirmPassword") }}</p>
<p>
{{ form.render("confirmPassword") }}
{{ form.messages("confirmPassword") }}
</p>
<p>
{{ form.render("terms") }} {{ form.label("terms") }}
{{ form.messages("terms") }}
</p>
<p>{{ form.render("Sign Up") }}</p>
{{ form.render("csrf", ["value": security.getToken()]) }}
{{ form.messages("csrf") }}
<hr>
{{ endForm() }}
~~~
- Welcome
- 安裝
- XAMPP 下的安裝
- WAMP 下安裝
- Apache 安裝說明
- Nginx 安裝說明
- Cherokee 安裝說明
- 使用 PHP 內置 web 服務器
- Phalcon 開發工具
- Windows 系統下使用 Phalcon 開發工具
- Mac OS X 系統下使用 Phalcon 開發工具
- Linux 系統下使用 Phalcon 開發工具
- 教程 1:讓我們通過例子來學習
- 教程 2:INVO簡介
- 教程 3: 保護INVO
- 教程4: 使用CRUD
- 教程5: 定制INVO
- 教程6: V?kuró
- 教程 7:創建簡單的 REST API
- 依賴注入與服務定位器(Dependency Injection/Service Location)
- MVC 架構(The MVC Architecture)
- 使用控制器(Using Controllers)
- 使用模型(Working with Models)
- 模型關系(Model Relationships)
- 模型事件(Model Events)
- 模型行為(Model Behaviors)
- 模型元數據(Models Metadata)
- 事務管理(Model Transactions)
- 模型驗證(Validating Models)
- Working with Models (Advanced)
- Phalcon 查詢語言(Phalcon Query Language (PHQL))
- 緩存對象關系映射(Caching in the ORM)
- 對象文檔映射 ODM (Object-Document Mapper)
- 使用視圖(Using Views)
- 視圖助手 (Tags)(View Helpers (Tags))