ȥå   Խ ʬ Хåå ź ʣ ̾ѹ   ñ측 ǽ   إ   ǽRSS

PHP/Php Framework

Last-modified: 2010-03-10 () 12:10:36 (2816d)
Top / PHP / Php Framework

PHP

Php FrameworkפȤϡRuby on Rails줿PHPΥץ󥽡 ե졼Ǥ
Ruby on Rails褫Webץ곫ȯPHPdzѤǤե졼Ǥ

Php FrameworkѤˤå

  1. Ȥ줿PHPѤƳȯԤSmartyPEARʤɤñѲǽ
  2. O/Rޥåԥ󥰤ˤؤʥǡ١
  3. migrationˤǡ١ΥСȿǤǽ
  4. Хåɤȥեȥɤưפ˳ȯǽ
  5. ȯĶdevelopment(PC), test(ƥȥȤƥȼ¹), production(֥)ʬΤǡDB˱ƶͿȯǽ
  6. Υե졼˴ƤȡRuby on RailsΥץȤ򤷤䤹ʤ

Php FrameworkȳѤΤΥƥå

  1. ȥåץڡ򻲾
  2. 塼ȥꥢڡ򻲾ȤơPCXAMPPưƤߤ
  3. κݤʬˤϡΥڡ­dzǧ
  4. ɬפ˱Ruby on RailsؽƻͤȤ롣

塼ȥꥢΥPC³

եȥ
http://localhost/chiral_fw_sample/samples/application/app/apps_web/frontend/

Хå
http://localhost/chiral_fw_sample/samples/application/app/apps_web/backend/

ѥ̾ŬѤƤ

塼ȥꥢ­β

PhpFrameworkTutorialFrontendBbsList.gif

ιΥǡ줿ηǼĥꥹȲ̤Ǥ

ȥ룱 bbsʸ
   ȣ
   ȣ

ȥ룲 bbsʸ
   ȣ

̤bbsǤ

PhpFrameworkTutorialBackendBbsList.gif

̤commentǤ

PhpFrameworkTutorialBackendCommentList.gif

塼ȥꥢ­ơ֥δϢ

bbsơ֥
    id
    subject     ... Ǽƥȥ
    body        ... Ǽʸ
    created_at
    updated_at
    'relations' => array(
        'Comment' => 'item',   ... Ҷcommentơ֥Ǥ
                                   ƣĤФƻҶʣƤޤ
                                   ơ  ΤδطǤ
    )
    function after_delete() 
    {
        $cnt = $this->delete_items('Comment'); ... ʸȤϡãΥȤ
    }
commentơ֥
    id
    bbs_id      ... (bbs)idɳդ
    body        ... ʸ
    created_at
    updated_at
    'relations' => array(
        'Bbs' => 'header',     ... Ƥbbsơ֥Ǥ
                                   ҶĤФƿƤϣĤǤ
    )

塼ȥꥢ­ǼĥꥹȤΥӥ塼񤭴뤢

app/apps/frontend/views/bbs/list.html

<h2><?php echo Application_Text::get('TITLE_LIST',
    array('name' => Fw_Record_Config::tablename('Bbs'))); ?></h2>
                others/texts/Application_Text_Japanese.phpƤ
                  ܸեޥåȤ˹碌"{name}"ɽޤ
                  'name'Fw_Record_Config::tablename('Bbs')Ȥơ֥ɽ̾Ϥޤ
                  ơ֥ɽ̾common/models/Bbs.phpޤ

<?php echo $this->link(Application_Text::get('LINK_ADD'), array('action' => 'edit')); ?><br />
                  link(ɽ̾, )
                    Ǥ˼ȤƱȥ顼(bbs)ǡedit_actionϤƤޤ

<?php $this->output_pager_link($this->pager, $this->pager_params); ?>
             pagerѤȤΤ褦ޤ

<table border=1>
  <tr>
    <td><?php echo Fw_Record_Config::columnname('Bbs','id');?></td>
    <td><?php echo Fw_Record_Config::columnname('Bbs','subject');?></td>
    <td><?php echo Fw_Record_Config::columnname('Bbs','body');?></td>
    <td><?php echo Fw_Record_Config::columnname('Bbs','created_at');?></td>
    <td><?php echo Fw_Record_Config::columnname('Bbs','updated_at');?></td>
  </tr>
  <?php foreach($this->pager->page_list() as $row){ ?>
        pagerѤȤΥ롼פǤ
  <tr>
    <td><?php echo ht($row->id); ?></td>
    <td><?php echo ht($row->subject); ?></td>
    <td><?php echo ht($row->body); ?></td>
    <td><?php echo ht($row->created_at); ?></td>
    <td><?php echo ht($row->updated_at); ?></td>
    <td>
      <?php echo $this->link(Application_Text::get('LINK_EDIT'),
          array('action' => 'edit', 'id' => $row->id())); ?>
                  link(ɽ̾, )
                    Ǥ˼ȤƱȥ顼(bbs)ǡedit_action
                    ˲äidϤƤޤ
    </td>
    <td>
      <?php echo $this->link(Application_Text::get('LINK_DELETE'),
          array('action' => 'delete', 'id' => $row->id()),
          array('confirm' => Application_Text::get('CONFIRM_DELETE'))); ?>
                         link(ɽ̾, , ǧ)
    </td>
  </tr>
  <tr>
    <td colspan="7">

      <h3><?php echo Application_Text::get('TITLE_LIST',
          array('name' => Fw_Record_Config::tablename('Comment'))); ?></h3>

      <?php echo $this->link(Application_Text::get('LINK_ADD'),
          array('controller' => 'comment', 'action' => 'edit', 'bbs_id' => $row->id())); ?><br />
                     link(ɽ̾, )
                       controller, action, ѥ᡼ꤷޤ
                       ѥ᡼ϥȥ¦$_REQUEST['bbs_id']ȤȼǤޤ
                           if (isset($_REQUEST['bbs_id']) && $_REQUEST['bbs_id']) {
                               $this->comment->bbs_id = $_REQUEST['bbs_id'];
                           }

      <table border=1>
        <tr>
          <td><?php echo Fw_Record_Config::columnname('Comment','id');?></td>
          <td><?php echo Fw_Record_Config::columnname('Comment','body');?></td>
          <td><?php echo Fw_Record_Config::columnname('Comment','created_at');?></td>
          <td><?php echo Fw_Record_Config::columnname('Comment','updated_at');?></td>
                         줾եɽ̾Ϥޤ
                           common/models/Comment.phpμ̤Ǥ
Fw_Record_Config::set('Comment', array(
    'tablename' => 'comment',         ... ơ֥ɽ̾
    'columnnames' => array(
        'id' => 'id',                 ... եɽ̾
        'bbs_id' => 'bbs_id',         ... 
        'body' => 'body',             ... 
        'created_at' => 'created_at' ,... 
        'updated_at' => 'updated_at' ,... 
    ),
    'relations' => array(
        'Bbs' => 'header',
    ),

        </tr>
        <?php foreach($row->r('Comment')->findall(array('order' => 'id')) as $row_comment){ ?>
               ƥ֥ȤäƤ뤹٤ƤλҤforeachǥ롼פ뤳ɽˡϤΤޤ޳Фޤ礦

        <tr>
          <td><?php echo ht($row_comment->id); ?></td>
          <td><?php echo ht($row_comment->body); ?></td>
          <td><?php echo ht($row_comment->created_at); ?></td>
          <td><?php echo ht($row_comment->updated_at); ?></td>
          <td>
            <?php echo $this->link(Application_Text::get('LINK_EDIT'),
                array('controller' => 'comment', 'action' => 'edit', 'id' => $row_comment->id())); ?>
          </td>
          <td>
            <?php echo $this->link(Application_Text::get('LINK_DELETE'),
                array('controller' => 'comment', 'action' => 'delete', 'id' => $row_comment->id()),
                array('confirm' => Application_Text::get('CONFIRM_DELETE'))); ?>
          </td>
        </tr>
        <?php } ?>
      </table>
    </td>
  </tr>


  <?php } ?>
</table>

塼ȥꥢ­̥ȥåפΥӥ塼񤭴뤢

񤭴δ̥ȥå

PhpFrameworkTutorialBackendTop.gif
app/apps/backend/views/_layouts/application.html

<html>
<head>
<?php echo $this->get('_common/head.html'); ?>
      󥯥롼ɤϤΤ褦˵Ҥޤ
        ľΥǥ쥯ȥ꤬١Ǥ
</head>
<body>
  <h1>Sample Application Backend</h1>

  <div style="background-color: #aa9999;">
<?php if(Application_Util::get_auth()->is_login()){?>
  Login ID: <?php echo h(Application_Util::get_auth()->info()->loginid); ?>
<?php }?>
  </div>
  󤷤ƤȤϥIDɽ

  󤷤ƤȤϥȲ̤ؤΥ󥯤ɽ
<?php if(Application_Util::get_auth()->is_login()){?>
  <div style="background-color: #cccccc;">
    <?php echo $this->link_dynamic(
        'Logout',
        array('controller' => 'auth', 'action' => 'logout',),
        array('class' => 'link_dynamic_link'),
        array('class' => 'link_dynamic_font')); ?> 
        $this->link_dynamic()ѤȥХѥΥ󥯤ޤϡ
            ɽ̾
            
            󥯤cssʤ°
            եȤcssʤ° ... ȤƤʤ褦Ǥ

          Τ褦˥֥饦Ϥޤ
            <a class="link_dynamic_link"
             href="/chiral_fw_sample/samples/application/app/apps_web/backend/auth/logout/">
             Logout</a> 

  </div>
<?php }?>

    <?php echo $this->link_dynamic(
        Fw_Record_Config::tablename('Bbs'),
        array('controller' => 'bbs', 'action' => 'list',),
        array('style' => 'color:#2222bb'),
        array('style' => 'color:#22aa22')); ?>
           Τ褦˥֥饦Ϥޤ
              <a style="color:#2222bb"
               href="/chiral_fw_sample/samples/application/app/apps_web/backend/bbs/list/">
               bbs</a>

    <?php echo $this->link_dynamic(
        Fw_Record_Config::tablename('Comment'),
        array('controller' => 'comment', 'action' => 'list',),
        array('style' => 'color:#2222bb'),
        array('style' => 'color:#22aa22')); ?>
           Τ褦˥֥饦Ϥޤ
                <a style="color:#2222bb"
                 href="/chiral_fw_sample/samples/application/app/apps_web/backend/comment/list/">
                 comment</a>

<?php if(Fw_Controller_Flash::exists('notice')){?>
<div class="notice"><?php echo Fw_Controller_Flash::get('notice')?></div>
<?php }?>
ե졼Noticeͭɽޤ

<div>
  <?php echo $this->contents; ?>
</div>
ȥ顼ʸǤ

<?php
$trace_string = Fw_Controller_Debug::trace_string();
echo $trace_string;
?>

developĶǤΥȥ졼ϤǤ

</body>
</html>

ӥ塼

Ruby on Railsƥץ졼(ĥҤ.rhtml)

<% Rubyץ %>
<%= ϤRubyץ %>
<%=h ʸϤRubyץ %>

Php Framework̾ƥץ졼(ĥҤ.html)

<?php PHPץ; ?>
<?php echo PHPʸ; ?>
<?php echo ht(ʸPHPʸ); ?>

<?php echo PHPʸ; ?>ǡ֥PHPʸפˤ褯񤫤ե졼

membersơ֥uidեɽ̾Fw_Record_Config::columnname('Member','uid')
ޥåԥ󥰤줿member֥Ȥuidեͤhtmlפht($this->member->uid)
ɽ̾career_hash򻲾Ȥɽ$this->career_hash[ $this->member->career_id ]
member֥nameեɤϤƥȥܥå(50)$this->record("textbox", "member", "name", array('size' => '50')
member֥announceեɤϤƥȥꥢ$this->record("textarea", "member", "announce", array('rows' => '20', 'cols' => '50'))
member֥nameեɤϤ$this->record("select", "member", "sex", $this->SEX_HASH, array(), array('include_blank' => true))
ǥ˥ޥåԥ󥰤Ƥʤƥȥܥå ȥ餫$_REQUEST['point_up_down']ǻ$this->textbox("point_up_down", "", array('size' => '20', 'style' => 'text-align:right'))

Php Framework Smartyƥץ졼(ĥҤ.tpl)

{ *  *}
{ Smartyʸ }
{ include file="info/_type_detail_`$content_type_id`.tpl" }