使用可能なコマンドの確認
使用可能なコマンドの確認は「phalcon commands」で行います。
といってもそんなに多くありません。
$ phalcon commands
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)
基本的にhogeとcreate-hogeはエイリアスとなっているようです。
プロジェクトの作成
$ phalcon create-project store
storeというディレクトリ名でphalconのプロジェクトが作成されます。
ビルトインサーバーの起動
phalconのアプリがあるディレクトリまでいき、以下を実行。
$ php -S localhost:8000 -t /public .htrouter.php
controller作成
Phalcon projectの下で以下を実行
app/controllers/PostController.phpが作成される
$ phalcon create-controller post
DBとの接続
modelsやscaffoldを使うために、databaseへの接続準備が必要なのですが、
app/config/config.php.で行います。
databaseのセクションを変更します。
app/config/config.php
<?php
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');
return new \Phalcon\Config([
'database' => [
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'root',
'password' => 'secret',
'dbname' => 'test',
'charset' => 'utf8',
],
'application' => [
'appDir' => APP_PATH . '/',
'controllersDir' => APP_PATH . '/controllers/',
'modelsDir' => APP_PATH . '/models/',
'migrationsDir' => APP_PATH . '/migrations/',
'viewsDir' => APP_PATH . '/views/',
'pluginsDir' => APP_PATH . '/plugins/',
'libraryDir' => APP_PATH . '/library/',
'cacheDir' => BASE_PATH . '/cache/',
// This allows the baseUri to be understand project paths that are not in the root directory
// of the webpspace. This will break if the public/index.php entry point is moved or
// possibly if the web server rewrite rules are changed. This can also be set to a static path.
'baseUri' => preg_replace('/public([\/\\])index.php$/', '', $_SERVER["PHP_SELF"]),
]
]);
モデルの作成
qiita.rb
$ phalcon model Posts