app2641/garnet-beans

There is no license information available for the latest version (0.3) of this package.

0.3 2014-05-21 01:51 UTC

This package is not auto-updated.

Last update: 2024-03-16 12:54:30 UTC


README

GarnetBeans は俺々モデルクラスだ。

Requires

GarnetBeans では、内部で EmeraldBeans と SapphireBeans が動作している。
EmeraldBeans
SapphireBeans

定数の設定と準備

GarnetBeans を動かすには LIB と APP という定数が必要になる。
LIB はディレクトリのパスを、 APP にはアプリケーション名を指定する。

<?php
define('LIB', '/Users/hoge/Desktop/app/library');
define('APP', 'App');

LIB に指定したディレクトリの直下には APP で指定したアプリケーション名の空ディレクトリを生成する。

$ mkdir ~/Desktop/app/library/App

モデルクラスの生成

モデルクラスは EmeraldBeans のコマンドクラスを使用して生成する。

$ touch run
$ chmod +x run
<?php
use Emerald\CLI;

$cli = CLI::getInstance();
$cli->execute($argv);

GenerateModel コマンドを実行すると引数に与えたモデルクラスが生成される。

$ ./run GenerateModel User
generated UserModel!

モデルクラスの使い方

モデルファクトリクラスを介してモデルクラスは取得する。 下記のように使う。

<?php
use Garnet\Container,
	App\Factory\ModelFactory;
	
$container  = new Container(new ModelFactory);
$user_model = $container->get('UserModel');

$user_model->fetchById(1);
echo $user_model->get('name');