Welcome! ようこそ! 歡迎訪問!

My IP Address

软件下载中心

Moony

MoonyϡPHPǵҤ줿̤Webץꥱե졼Ǥ
ƥץ졼ȥ󥸥ȤSmartyѤƤޤ ʳȯ: Moony::log

  1. ưĶ
  2. 󥹥ȡ
  3. 塼ȥꥢ

ưĶ

󥹥ȡ

pearѤƥ󥹥ȡ뤹ʲ˼ޤ
pearѤʤϡǤդΥǥ쥯ȥŸ֤Ƥ

  1. Moony-0.10.4.tgzɤޤ
  2. ʲΥޥɤ¹Ԥޤ
    $ pear install /path/to/Moony-0.10.4.tgz
  3. Smarty򥤥󥹥ȡ뤷Ƥʤϡʲμǥ󥹥ȡǽǤ
    $ pear channel-discover pearified.com
    $ pear install pearified/Smarty
  4. Moony򥢥󥤥󥹥ȡ뤹ϡʲΥޥɤ¹Ԥޤ
    $ pear uninstall __uri/Moony

Υե

ǥѥåȤindex.phpѰա/index.php/foo.html˥:

  1. 饤 index.php ʥǥѥå
  2. index.php Moony ǥѥå
  3. Moony Moony_Controller ʥ󥹥Ƽ
  4. Moony_Controller Moony_Router ʥ̾η
  5. Moony_Controller Moony_Request ʥꥯȥѥ᡼Ǽ
  6. Moony_Controller Moony_Response ʥ쥹ݥ
  7. Moony_Controller Moony_Session ʥåϡ
  8. Moony_Controller Moony_Flash Flashѿꥹȥ
  9. Moony_Controller Moony_View ʥǥեȥƥץ졼̾Τ
  10. Moony_Controller Moony_Plugins SmartyΥץ饰
  11. Moony_Controller Foo
  12. Moony_Controller Moony_Injector 󥸥
  13. Moony_Controller Foo filter᥽åɤ¹ԡ
  14. Moony_Controller Foo validate᥽åɤ¹ԡ
  15. Moony_Controller Foo execute᥽åɤ¹ԡ
  16. Moony_Controller Moony_View ʲ

̾ηˡ

URLư륹ץȤΥޥåԥ󥰤Τե򵭽ҤɬפϤޤ
ȤưʲΤ褦˥ޥåԥ󥰤ޤ:

URL̾󥯥饹եƥץ졼ȥե
/index.php/foo.htmlFooFoo.phpFoo.tpl
/index.php/foo/bar.htmlFooBarFooBar.phpFooBar.tpl
/index.php/foo_bar.htmlFooBarFooBar.phpFooBar.tpl
/index.php/foo/bar/param.htmlFooBarFooBar.phpFooBar.tpl
/index.php/fooFooFoo.phpFoo.tpl
/index.php/foo/FooIndexFooIndex.phpFooIndex.tpl
/index.php/foo/index.htmlFooIndexFooIndex.phpFooIndex.tpl
/index.php/IndexIndex.phpIndex.tpl
/index.php/index.htmlIndexIndex.phpIndex.tpl

ĥҤϾ̵뤵졢URL2ܤޤǤ̾Ȥưޤ
ʹߤURLʸϡץꥱΥѥ᡼Ȥưޤ
̾ȤưؿϡMoony.phpѹǽǤ
ǥ쥯ȥ˥äϡindex˥äΤȤߤʤޤ

ǥ쥯ȥʤɡưĶ

󥯥饹γǼ衢ƥץ졼ȥեγǼ衢 եγǼ衢եνʤɤ򤽤줾ꤹ뤳ȤǤޤ Moonyβ줾Υ󥹥󥹥᥽åɤ¹ԤƤ

᥽å̾ǽꤷʤδ
setActionDir($action_dir)󥯥饹Ǽǥ쥯ȥaction
setTemplateDir($template_dir)ƥץ졼ȥեǼǥ쥯ȥtemplate
setWorkDir($work_dir)եǼǥ쥯ȥwork
setLogDir($log_dir)եǥ쥯ȥlog
setTemplateExtension($template_extension)ƥץ졼ȥեγĥҤtpl
setLeftDelimiter($left_delimiter)Smartyκڤʸ{
setRightDelimiter($right_delimiter)Smartyαڤʸ}

顼ν

ɽɬפʥƥץ졼ȥե뤬Ĥʤ硢404Not Foundˤ֤ޤ ޤץꥱǥ顼ȯ硢500Internal Server Errorˤ֤ޤ ξ󥰽Ԥޤ

塼ȥꥢ

ǥѥåμ

Smarty.class.phpMoony.php򥤥󥯥롼ɤޤ MoonyΥ󥹥󥹤ɬפ˱ƳƼԤdispatch᥽åɤ¹Ԥޤ

ʲ˼ޤ:

<?php
require_once '/path/to/Moony.php';
require_once '/path/to/Smarty.class.php';
$moony =& new Moony();
$moony->setLeftDelimiter('<{');
$moony->setRightDelimiter('}>');
$moony->dispatch();
?>

󥸥

󥯥饹Υ󥹥ѿФơ Moony륳ݡͥȤΥ󥹥󥹤󥸥󤵤ޤ ǥեȤǰʲΤ褦˥󥸥󤵤ޤ 󥹥ѿѰդƤʤ硢󥸥ϹԤޤ

󥹥ѿ̾󥸥󤵤륯饹
$requestMoony_Request
$responseMoony_Response
$sessionMoony_Session
$flashMoony_Flash
$smartySmarty

ޤǤդΥ饹Υ󥹥󥹤򥤥󥸥󤹤뤳ȤǤޤ Τ褦iniեѰաInjections˥:󥹥̾:饹̾򵭽Ҥޤ 饹Υեinclude_pathˤơPEAR̿̾§˽äƥޤ Foo_Calc饹ξFoo/Calc.phpMoony_DBMoony_Uploaderˡ Υ󥹥󥹤⥢󥯥饹˥󥹥ѿƤʤޤ

[Injections]
calc=Foo_Calc
db=Moony_DB
uploader=Moony_Uploader

iniեϡǥѥåɤ߹߻򤷤Ƥޤ

<?php
require_once '/path/to/Moony.php';
require_once '/path/to/Smarty.class.php';
$moony =& new Moony();
$moony->setConfigFile('/path/to/ini_file');
$moony->dispatch();
?>

󥯥饹μʼºݤν

ºݤνexecute᥽åɤ˵Ҥޤ ä˼Ԥʤ硢󥯥饹Τά뤳ȤǽǤ ξ硢˽ä̾ΤΥƥץ졼ȥե뤬ľɽޤ

class Foo
{
    function execute()
    {
        // ºݤν
    }
}

󥯥饹μʥꥯȥѥ᡼ͤλѴ

ꥯȥѥ᡼ͤѴϡ filter᥽åɤ˽򵭽Ҥޤѥ᡼ȤMoony_FilterΥ󥹥󥹤Ϥޤ

class Foo
{
    var $request;
    function filter($filter)
    {
        // 'furigana'ͤѥʤѴ
        $filter->toKatakana('furigana');
        // 'name'ͤ'foo'ä硢'bar'ִ
        if ($this->request->get('name') == 'foo') {
            $this->request->replace('name', 'bar');
        }
    }
}

󥯥饹μʥꥯȥѥ᡼ͤΥå

ꥯȥѥ᡼ͤåϡ validate᥽åɤ˽򵭽Ҥޤѥ᡼ȤMoony_ValidatorΥ󥹥󥹤Ϥޤ 顼줿硢ϸΥƥץ졼Ȥɽޤʥå󤬳ϤƤˡ

POSTäƽԤ󥯥饹:

class Register
{
    var $request;
    function validate($validator)
    {
        // validation顼λѥƥץ졼Ȥ
        $validator->setTemplate('Entry');

        // Moony_Validatorεǽ
        $validator->setRequired('name', '̾ɬϤƤ');
        $validator->setKatakana('furigana', 'եꥬʤϥʤϤƤ');

        // ȼڡʥ顼ξ硢顼å
        if ($this->request->get('foo_cd') != '1') {
            $validator->addError('foo_cd', 'CD꤬ޤ');
        }
    }
}

validation顼ΤϸΥƥץ졼ȥեܤˡ 顼åɽϥեΥƥץ졼ȤʲΤ褦ˤޤ ܤ˴ؤƤϡMoony_Plugins饹򻲾ȤƤ

ϥեΥƥץ졼ȥե:

{moony_errors header='<ul>' footer='</ul>' prefix='<li>' postfix='</li>'}
<form action="/index.php/register" method="POST">
եꥬ: <input type="text" name="furigana" value="{$furigana}" />
̾: <input type="text" name="name" value="{$name}" />
<input type="submit" />
</form>

ꥯȥѥ᡼μ

ꥯȥѥ᡼Moony_Request饹˳ǼƤޤ Υ饹˳ǼƤΤϡ餫NullХʸ󤬽졢ʸ󥳡ǥ󥰤ѴԤ줿ͤǤ

class Foo
{
    var $request;
    function execute()
    {
        // 줾
        $user = $this->request->get('user');
        $pass = $this->request->get('pass');

        // ѥ᡼ץѥƥȤƻĥ֥Ȥ
        $obj = $this->request->toObject();
    }
}

URLȤϤ줿ѥ᡼μ

URLȤϤ줿ѥ᡼Moony_Request饹˳ǼƤޤ 㤨С/index.php/foo/bar/param1/param2.htmlȤURLξ:

class FooBar
{
    var $request;
    function execute()
    {
        $param1 = $this->request->getPathInfo(0);   // ʸ'param1'
        $param2 = $this->request->getPathInfo(1);   // ʸ'param2'
    }
}

å򰷤

åˤMoony_Session饹ͳǥޤ

class Foo
{
    var $request;
    var $session;
    function execute()
    {
        if ($this->session->exists('user')) {    // ¸߳ǧ
            $user = $this->session->get('user');  // 
        } else {
            $user = $this->request->get('user');
            $this->session->set('user', $user);   // 
        }
    }
}

Flashѿ򰷤

FlashѿϰŪͤǼΰǤMoony_Flash饹ͳǥޤ ºݤͤϥå˳Ǽ졢Υ󤬼¹ԤȤޤݻޤ μΥ󤬼¹Ԥ륿ߥ󥰤ǡFlashѿ˴ޤ

class Foo
{
    var $flash;
    function execute()
    {
        $user = $this->flash->get('user');   // 
        $this->flash->set('user', $user);    // 
        $this->flash->keep('user');          // Υ˰Ѥ
    }
}

ƥץ졼Ȥͤꤹ

Moony_Response饹Ѥޤ

class Foo
{
    var $response;
    function execute($request, $response)
    {
        $this->response->set('user', $user);        // ͤϥǥեȤǥ
        $this->response->setAll($items);            // ϢͤϥǥեȤǥ
        $this->response->set('user', $user, false); // Ū˥פʤ
        $this->response->setAll($items, false);     // ϢŪ˥פʤ
    }
}

Ѥƥץ졼ȥեѹ

Moony_Response饹Ѥޤ

class Foo
{
    var $response;
    function execute()
    {
        $this->response->setTemplate('Another');   // Another.tpl
    }
}

Moony_Response饹Ѥޤ ꥯȥѥ᡼ȥƥץ졼ȤꤷͤϼΥˤѤޤ

class Foo
{
    var $response;
    function execute()
    {
        $this->response->setNextAction('NextAction');
    }
}

̤URL˥쥯ȤԤ

Moony_Response饹Ѥޤ

class Foo
{
    var $response;
    function execute()
    {
        $this->response->redirect('http://example.com/');   // example.com
    }
}

桼ФƥեΥɤԤ

Moony_Response饹Ѥޤ

class Foo
{
    var $response;
    function execute()
    {
        $this->response->sendFile('/path/to/attachment_file');   // attachment_file
    }
}

եΥåץɤԤ

Moony_Uploader饹Ѥޤ

<form action="/index.php/upload" enctype="multipart/form-data" method="POST">
  <input type="file" name="userfile" />
  <input type="submit" value="send" />
</form>

嵭Τ褦ʥեब硢ʲΤ褦˵Ҥ뤳Ȥǥե륢åץɽԤȤǤޤ iniեMoony_UploaderΥ󥸥꤬ԤƤˡ

class Upload
{
    var $request;
    var $uploader;
    function execute()
    {
        $uploader->setTarget($this->request, 'userfile');
        $uploader->setEncoding('SJIS');
        if ($uploader->upload('/path/to/save_dir', 'save_file_name', 0644)) {
            // åץ
        } else {
            // åץɼ
        }
    }
}

󥸥եMoony_Uploader饹ꤵ줿硢 Moony_UploaderΥ󥹥󥹤󥯥饹Υ󥹥ѿȤƥ󥸥󤵤ޤ

ñʥƥȤνϤԤ

Moony_Response饹ѤޤMoony_Response::outputʣ¹Ԥ뤳ȤǽǤ 2ܤΰȤʸ󥳡ǥ󥰤λ꤬ǽǤν¹Ԥ줿硢 ƥץ졼ȤΥ󥰽ϼ¹ԤޤAjaxˤбǽǤ

class Foo
{
    var $response;
    function execute()
    {
        $this->response->output('ϤƥȤ', 'UTF-8');
    }
}

ȥ󥶥ȡΥåԤ

Moony_RequestѤޤޤեΥƥץ졼Ȥ˰ʲΤ褦˵Ҥޤ

<form action="/index.php/foo" method="POST">
  {moony_token xhtml=true}   {* XHTMLȤƽϤʤ硢xhtml=trueεҤ *}
</form>
ȡɽ˰ʲΤ褦ŸޤSmartyΥץ饰ǽѡˡ
<form action="/index.php/foo" method="POST">
  <input type="hidden" name="_moony_token" value="..." />
</form>
ΥեPOSTꥯȤ륢󥯥饹ǡȥ󥶥ȡåԤޤ ʲΤ褦˵Ҥ뤳ȤǥåԤȤǤޤ
class Foo
{
    var $request;
    var $session;
    function execute()
    {
        if ($this->request->checkToken()) {
            // ȡ
        } else {
            // ʥȡ
        }
    }
}

Moony_DBȤ

Moony_DBPEAR::DBѤñʥǡ١饹Ǥ ץ졼ۥޤSQL¹Ԥ ̤ܤ̾Τ򥭡ȤϢȤ֤ޤ ޤͤʸ󥳡ǥ󥰤ѴưǹԤޤ

$db =& new Moony_DB();
$db->connect($dsn, 'EUC-JP');   // DBʸ󥳡ǥ󥰤EUC-JPξ
$result = $db->query('select id,name from user where id=?', array($user_id));
$db->disconnect();
foreach($result as $row) {
    print 'id: ' . $row['id'] . ', name: ' . $row['name'] . "\n";
}

󥸥եMoony_DB饹ꤵ줿硢 Moony_DBΥ󥹥󥹤󥯥饹Υ󥹥ѿȤƥ󥸥󤵤ޤ

ϤԤ

Moony_Logger饹Ѥ뤳ȤǥƥȥϲǽǤ ޤMoony.phpMOONY_LOG_CATEGORYͤѹ뤳Ȥ ϤԤ٥ͤԤȤǤޤ ʽͤMOONY_LOG_LEVEL_INFOǡdebugϽϤޤ󡣡

Moony_Logger::fatal('message');   // ̿Ū顼
Moony_Logger::error('message');   // 顼
Moony_Logger::warn('message');    // ٹ
Moony_Logger::info('message');    // ̾
Moony_Logger::debug('message');   // ǥХå
Moony_Logger::info('message', __FILE__);             // ե̾
Moony_Logger::info('message', __FILE__, __LINE__);   // եֹ̾

Moonyǭ ĿŪ˺Ƥ륢ץꥱǤ
BSD饤˴ŤۤƤޤ