Introduction
Please watch over gently🙇♀️
I will write about cakePHP "cell"!
How to use
- Create 'class' and 'template'
[src/View/Cell/InboxCell.php]
<?php namespace App\View\Cell; use Cake\View\Cell; class InboxCell extends Cell { public function display() { $hello = "hello!!!(*´ω`*)"; $this->set('sample', $hello); } }
[templates/cell/Inbox/display.php]
<div> message✨ <?= $sample ?> </div>
use
On the "/templates/????/index.php"
The following description
<?=$this->cell('Inbox::display');?>
display
A little more
Show what you get in the model
Assumption: You have a created model.This time 'tags'
[src/View/Cell/InboxCell.php]
<?php namespace App\View\Cell; use Cake\View\Cell; class InboxCell extends Cell { public function display() { $this->loadModel('Tags'); $tags = $this->Tags->find(); $this->set('tags', $tags); } }
[templates/cell/Inbox/display.php]
<table> <?php foreach ($tags as $tag): ?> <tr> <td><?= $tag->title ?></td> </tr> <?php endforeach; ?> </table>
Where you want to use↓
<?=$this->cell('Inbox::display');?>
display
Overall picture
Don't forget the escape
I forgot,
So I will not forget
↓
[templates/cell/Inbox/display.php]
h($tag->title)
Top comments (0)