DEV Community

Cover image for Create cell【CakePHP】
sachiko-kame
sachiko-kame

Posted on

1 1

Create cell【CakePHP】

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);
    }

}

Enter fullscreen mode Exit fullscreen mode

[templates/cell/Inbox/display.php]

<div>
    message✨ <?= $sample ?> 
</div>
Enter fullscreen mode Exit fullscreen mode

use

On the "/templates/????/index.php"

The following description

<?=$this->cell('Inbox::display');?>

display

http://〇〇/????
スクリーンショット 2020-09-06 17.44.56

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);
    }

}
Enter fullscreen mode Exit fullscreen mode

[templates/cell/Inbox/display.php]

<table>
  <?php foreach ($tags as $tag): ?>
    <tr>
      <td><?= $tag->title ?></td>
    </tr>
  <?php endforeach; ?>
</table>
Enter fullscreen mode Exit fullscreen mode

Where you want to use↓

<?=$this->cell('Inbox::display');?>

display

スクリーンショット 2020-09-06 18.15.20

Overall picture

スクリーンショット 2020-09-06 18.31.39

Don't forget the escape

I forgot,
So I will not forget

[templates/cell/Inbox/display.php]

h($tag->title)
Enter fullscreen mode Exit fullscreen mode

reference

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay