CakePHP View謫堺ス

繝繝ウ繝励Ξ繝シ繝

繝繝ウ繝励Ξ繝シ繝医ヵ繧。繧、繝ォ


笏敗rc
縲笏乃emplate
縲縲笏Hello
縲縲縲笏auto_layout_false.ctp
縲縲縲笏auto_layout_true.ctp
縲縲縲笏猫ayout
縲縲縲縲笏default.ctp
縲縲縲縲笏hello.ctp

窶サ繝輔ぃ繧、繝ォ蜷阪ッ繧ケ繝阪シ繧ッ蠑縺ァ險倩ソー縺吶k

繝薙Η繝シ繝繝ウ繝励Ξ繝シ繝

窶サ繧ウ繝ウ繝医Ο繝シ繝ゥ
class HelloController extends AppController {

縲public function autoLayoutFalse(){
縲縲繝薙Η繝シ繝繝ウ繝励Ξ繝シ繝(Template\(繧ッ繝ゥ繧ケ蜷)\(繧「繧ッ繧キ繝ァ繝ウ蜷).ctp)菴ソ逕ィシ壽怏
縲縲$this->autoRender = true;

縲縲繝薙Η繝シ縺ク蛟、繧帝」謳コ(縲Controler竊歎iew繝繝シ繧ソ騾」謳コ縲榊盾辣ァ)
縲縲$this->set('cakeDescription', 'autoLayoutシ哥alse');

縲縲繝ャ繧、繧「繧ヲ繝(Template\Layout\default.ctp)菴ソ逕ィシ夂┌
縲縲$this->viewBuilder()->autoLayout(false);
縲}
}

窶サauto_layout_false.ctp
<!DOCTYPE html>
<html>
<head>
縲縲<?= $this->Html->charset() ?>
縲縲<meta name="viewport" content="width=device-width, initial-scale=1.0">
縲縲<title><?= $cakeDescription ?></title>
縲縲<?= $this->Html->meta('icon') ?>
縲縲<?= $this->Html->css('base.css') ?>
縲縲<?= $this->Html->css('cake.css') ?>
縲縲<?= $this->Html->css('home.css') ?>
</head>
<body>
縲縲<footer>autoLayoutFalse</footer>
</body>
</html>

窶サ螳溯。檎オ先棡(ス/hello/autoLayoutFalse)

繝ャ繧、繧「繧ヲ繝

窶サ繧ウ繝ウ繝医Ο繝シ繝ゥ
class HelloController extends AppController {

縲public function beforeFilter(Event $event){
縲縲parent::beforeFilter($event);
縲縲繝薙Η繝シ繝繝ウ繝励Ξ繝シ繝(Template\(繧ッ繝ゥ繧ケ蜷)\(繧「繧ッ繧キ繝ァ繝ウ蜷).ctp)菴ソ逕ィシ壽怏
縲縲$this->autoRender = true;

縲縲繝ャ繧、繧「繧ヲ繝医ヵ繧。繧、繝ォ(Template\Layout\hello.ctp)謖螳
縲縲$this->viewBuilder()->layout("Hello");
縲縲繝ャ繧、繧「繧ヲ繝医ヵ繧。繧、繝ォ譛ェ謖螳壽凾縺ッdefault.ctp縺御スソ逕ィ縺輔l繧

縲縲繝ャ繧、繧「繧ヲ繝(Template\Layout\ス.ctp)菴ソ逕ィシ壽怏
縲縲$this->viewBuilder()->autoLayout(true);
縲}
縲竊薙→蜷後§
public function autoLayoutTrue(){}
}

窶サauto_layout_true.ctp
autoLayoutTrue

窶サ竊 髱柯tml

窶サhello.ctp
<!DOCTYPE html>
<html>
<head>
縲縲<?= $this->Html->charset() ?>
縲縲<meta name="viewport" content="width=device-width, initial-scale=1.0">
縲縲<title>
縲縲縲縲<?= $cakeDescription ?>:
縲縲縲縲<?= $this->fetch('title') ?>
縲縲</title>
縲縲<?= $this->Html->meta('icon') ?>
縲縲<?= $this->Html->css('base.css') ?>
縲縲<?= $this->Html->css('cake.css') ?>
縲縲<?= $this->fetch('meta') ?>
縲縲<?= $this->fetch('css') ?>
縲縲<?= $this->fetch('script') ?>
</head>
<body>
縲縲<div>
縲縲縲autoLayout驛ィ蛻
縲縲</div>
縲縲竊 縺薙%縺ォauto_layout_true.ctp縺ョ蜀螳ケ縺悟沂繧∬セシ縺セ繧後k
縲縲<div class="container clearfix">
縲縲縲縲<?= $this->fetch('content') ?>
縲縲</div>
</body>
</html>

窶サ螳溯。檎オ先棡(ス/hello/autoLayoutTrue)

繝ャ繧、繧「繧ヲ繝医ヵ繧。繧、繝ォ螟画焚縺ク縺ョ繝繝シ繧ソ騾」謳コ

public function beforeRender($view = null, $layout = null) {
縲$this->set('point', 1000);
縲$this->set('user_name', 'aaa');
縲return parent::beforeRender($view, $layout);
}

繝倥Ν繝代シ繝。繧ス繝繝

Form繝倥Ν繝代シ繝。繧ス繝繝

CakePHP View謫堺ス Form繝倥Ν繝代シ縲榊盾辣ァ

Html繝倥Ν繝代シ繝。繧ス繝繝

CakePHP View謫堺ス Html繝倥Ν繝代シ縲榊盾辣ァ

Number繝倥Ν繝代シ繝。繧ス繝繝

<?= $this->Number->format(10000); ?>
竊10,000

Controler竊歎iew繝繝シ繧ソ騾」謳コ

騾壼クク

窶サControler
$this->set('data', 'aaa');

螟画焚蜷阪′蜷後§縺ョ蝣エ蜷
$this->set('val1'), $val1);
$this->set('val2'), $val2);
$this->set('val3'), $val3);

$this->set(compact('val1', 'val2', 'val3'));

窶サview(test.ctp)
<php? echo $data; ?>
竊誕aa

繝壹シ繧ク繧ク繝ウ繧ー蜃ヲ逅

$this->繝「繝繝ォ蜷 = array(
縲繝「繝繝ォ蜷 => array(
縲縲'fields' => ス,
縲縲'conditions' => ス,
縲縲'order' => ス,
縲)
);
繝繝シ繧ソ縺ョ蜿門セ玲婿豕輔↓縺、縺縺ヲ縺ッ縲繝励Ο繧ー繝ゥ繝險隱 繝繝シ繧ソ繝吶シ繧ケ謫堺ス/驟榊励∈縺ョ荳諡ャ蜿門セ縲榊盾辣ァ

View縺ク繝繝シ繧ソ騾」謳コ
$this->set('data', $this->paginate('繝「繝繝ォ蜷'));

View蛛エ
<table class="list">
縲<thead>
縲縲<tr>
縲縲縲陦ィ遉コ繝ゥ繝吶Νシ壹悟膚蜩∝錐縲肴款荳九〒繧ス繝シ繝
縲縲縲<th scope="col"><?= $this->Paginator->sort('product_name', '蝠蜩∝錐') ?></th>
縲縲縲<th scope="col"><?= $this->Paginator->sort('genre', '繧ク繝」繝ウ繝ォ') ?></th>
縲縲縲<th scope="col"><?= $this->Paginator->sort('created', '逋サ骭イ譌・') ?></th>
縲縲</tr>
縲</thead>
縲<tbody>
縲縲<?php foreach ($products as $product): ?>
縲縲<tr>
縲縲縲<td>
縲縲縲縲<?= $this->Html->link($product->product_name, ['action' => 'movie_detail', $product->id]) ?>
縲縲縲</td>
縲縲縲<td><?= $this->Number->format($product->genre) ?></td>
縲縲縲<td><?= h($product->created->i18nFormat('YYYY/MM/dd')) ?></td>
縲縲</tr>
縲縲<?php endforeach; ?>
縲</tbody>
</table>
<div class="paginator">
縲<ul class="pagination">
縲縲<?= $this->Paginator->first('<< ' . __('first')) ?>
縲縲<?= $this->Paginator->prev('< ' . __('previous')) ?>
縲縲<?= $this->Paginator->numbers() ?>
縲縲<?= $this->Paginator->next(__('next') . ' >') ?>
縲縲<?= $this->Paginator->last(__('last') . ' >>') ?>
縲</ul>
縲<p><?= $this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?></p>
</div>

繝「繝繝ォ謫堺ス

縲尽elect譛峨j縲
窶サ繧ウ繝ウ繝医Ο繝シ繝ゥ
$this->繝「繝繝ォ1
縲縲->find()
縲縲->contain(['seconds'])
縲縲->where(ス)
縲縲->select([
縲縲縲縲'id',
縲縲縲縲'col1',
縲縲縲縲'col2',
縲縲縲縲'seconds.col1',
縲縲縲縲'seconds.col2',
縲縲]);

窶サ繝薙Η繝シ
<?php foreach ($models as $model): ?>
縲<tr>
縲縲縲<td><?= $model->id) ?></td>
縲縲縲<td><?= $model->col1 ?></td>
縲縲縲<td><?= $model->col2 ?></td>
縲縲縲竊薙Δ繝繝ォ蜷阪°繧峨茎縲阪r髯、蜴サ縺吶k蠢隕√′縺ゅk
縲縲縲<td><?= $model->second->col1 ?></td>
縲縲縲<td><?= $model->second->col1 ?></td>
縲</tr>
<?php endforeach; ?>

縲尽elect辟。縺励
窶サ繧ウ繝ウ繝医Ο繝シ繝ゥ
$this->繝「繝繝ォ1
縲縲->find()
縲縲->contain(['seconds'])
縲縲->where(ス)
縲;

窶サ繝薙Η繝シ
<?php foreach ($models as $model): ?>
縲<tr>
縲縲縲<td><?= $model->id) ?></td>
縲縲縲<td><?= $model->col1 ?></td>
縲縲縲<td><?= $model->col2 ?></td>
縲縲縲竊薙Δ繝繝ォ蜷阪ョ驟榊
縲縲縲<td><?= $model->seconds['col1'] ?></td>
縲縲縲<td><?= $model->seconds['col1'] ?></td>
縲</tr>
<?php endforeach; ?>

Follow me!