LoginSignup
4
4

More than 5 years have passed since last update.

FuelPHPでDoctrine2のコマンドを使えるようにするやり方

Posted at

ここ連日Doctrine2と戯れていますが、コマンドが使えないと非常に不便なので何とかした話。
全然難しいことはなかったので、後回しにするんじゃなかった。

事前準備

以前の記事と同じ構成の環境を使うので、同じ様にセットアップしておく。
http://qiita.com/gyhino@github/items/188d207d26f608269b3a

やることの整理

  1. コマンドの在処の確認
  2. 設定
  3. 使えるか確認

コマンドの在処の確認

Doctrine2のコマンドはcomposerでインストールした場合、vendor/binに置かれている。
今回インストールした先は、app/vendorなのでapp/vendor/bin/doctrineが存在する。

oilに組み込むのを紹介している記事もあったが、そのまま使えるので今回はそのまま使うことにする。

設定

cli-config.phpを作って動くようにする。
実行時にカレントディレクトリ、もしくはカレントディレクトリのconfigディレクトリのcli-config.phpを読み込むので、
参照しやすい場所に置いておく。

今回はプロジェクトのrootディレクトリに置くことにした。(core,packages,appと同列の場所)

cli-config.php
<?php

/**
 * Website document root
 */
define('DOCROOT', __DIR__.DIRECTORY_SEPARATOR);

/**
 * Path to the application directory.
 */
define('APPPATH', realpath(__DIR__.'/fuel/app/').DIRECTORY_SEPARATOR);

/**
 * Path to the default packages directory.
 */
define('PKGPATH', realpath(__DIR__.'/fuel/packages/').DIRECTORY_SEPARATOR);

/**
 * The path to the framework core.
 */
define('COREPATH', realpath(__DIR__.'/fuel/core/').DIRECTORY_SEPARATOR);

// Boot the app
require APPPATH.'bootstrap.php';

// Setup ConsoleRunner
$em = \Fuel\Doctrine::manager();
return ConsoleRunner::createHelperSet($em);

使えるか確認

以下のコマンドでhelpが表示されれば使える。

./app/vendor/bin/doctrine

yamlなどからEntityを作りたい場合は、

./app/vendor/bin/doctrine orm:generate-entities ./app/classes

yamlなどからRepositoryを作りたい場合は、

./app/vendor/bin/doctrine orm:generate-repositories ./app/classes

という風に使う。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4