Entity 클래스 구조
// app/Entities/Post.php
namespace App\Entities;

use CodeIgniter\Entity\Entity;

class Post extends Entity
{
    // 타입 자동 캐스팅
    protected $casts = [
        'id'    => 'integer',
        'views' => 'integer',
    ];

    // 커스텀 메서드 - 본문 요약
    public function getExcerpt(int $length = 100): string
    {
        return mb_strlen($this->content) > $length
            ? mb_substr($this->content, 0, $length) . '...'
            : $this->content;
    }

    // 커스텀 메서드 - 날짜 포맷
    public function getFormattedDate(): string
    {
        return $this->created_at?->format('Y-m-d H:i') ?? '';
    }
}
← 모델로