edo1z blog

プログラミングなどに関するブログです

cakePHP2.3 エレメント・ブロック

http://book.cakephp.org/2.0/ja/views.html

// sidebarブロックを作成する
$this->start('sidebar');
echo $this->element('sidebar/recent_topics');
echo $this->element('sidebar/recent_comments');
$this->end();


// sidebarの末尾に追加する
$this->append('sidebar');
echo $this->element('sidebar/popular_topics');
$this->end();
// sidebarブロックから以前のコンテンツを消去する
$this->assign('sidebar', '');
// sidebarの先頭に追加する
$this->prepend('sidebar', 'this content goes on top of sidebar');
//ブロックの表示
echo $this->fetch('sidebar');
// in app/View/Layouts/default.ctp
<?php if ($this->fetch('menu')): ?>
<div class="menu">
    <h3>Menu options</h3>
    <?php echo $this->fetch('menu'); ?>
</div>
<?php endif; ?>
//ブロックのデフォルト値設定
<div class="shopping-cart">
    <h3>Your Cart</h3>
    <?php echo $this->fetch('cart', 'Your cart is empty'); ?>
</div>