themusicdev / cakephp-daisyui
daisyUI 5 view helpers for CakePHP 5
Package info
github.com/TheMusicDev/cakephp-daisyui
Type:cakephp-plugin
pkg:composer/themusicdev/cakephp-daisyui
Requires
- php: >=8.2
- cakephp/cakephp: ^5.2
Requires (Dev)
- cakephp/cakephp-codesniffer: ^5.3
- captainhook/captainhook: ^5.29
- captainhook/hook-installer: ^1.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.5.5 || ^11.1.3
- ramsey/conventional-commits: ^1.7
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-29 06:10:24 UTC
README
daisyUI 5 view helpers for CakePHP 5.
Built by TheMusicDev LLC, MIT licensed.
- daisyUI 5, Tailwind CSS 4, CakePHP ^5.2, PHP >= 8.2
- One helper per daisyUI category, plus daisyUI-styled
Form,Paginator,FlashandBreadcrumbshelpers — so a CakePHP app can go fully daisyUI with no other package.
Install
themusicdev/cakephp-daisyui on Packagist:
composer require themusicdev/cakephp-daisyui bin/cake plugin load TheMusicDev/DaisyUi
Loading the helpers
Add the trait to your AppView and call loadDaisyUi():
// src/View/AppView.php use TheMusicDev\DaisyUi\View\DaisyUiViewTrait; class AppView extends View { use DaisyUiViewTrait; public function initialize(): void { $this->loadDaisyUi(); } }
This registers these twelve helpers:
| Helper | daisyUI category |
|---|---|
Actions |
Actions (button, dropdown, fab, modal, swap, theme controller) |
DataDisplay |
Data display (badge, card, …) |
DataInput |
Data input — redirect stubs; these components belong to Form |
Feedback |
Feedback (alert, loading, progress, …) |
Layout |
Layout (divider, drawer, …) |
Mockup |
Mockup (browser, code, phone, window) |
Navigation |
Navigation (dock, link, menu, …) |
Assets |
Pinned CDN CSS loading (see below) |
Form |
daisyUI-styled form controls (replaces the core helper) |
Paginator |
daisyUI-styled pagination (replaces the core helper) |
Flash |
daisyUI-styled flash messages (replaces the core helper) |
Breadcrumbs |
daisyUI-styled breadcrumbs (replaces the core helper) |
To load only some of them instead, register them yourself:
$this->addHelper('TheMusicDev/DaisyUi.Feedback');
The class map
Every daisyUI class the helpers emit comes from one flat map, keyed
{component}.{group}.{name}:
// config/class_maps/daisyui.php (excerpt) 'button.base' => 'btn', 'button.color.primary' => 'btn-primary', 'button.size.sm' => 'btn-sm',
Each modifier group (color, size, appearance, modifier, direction,
placement, behavior, alignment) is a method option, so class names are
never concatenated and Tailwind can always see them statically.
Swap the whole map (a map replaces the default entirely):
// Put your map in config/class_maps/mycustom.php, then: Configure::write('DaisyUi.classMap', 'mycustom');
The app's config/class_maps/{name}.php is preferred over the plugin's copy
of the same name.
Override single entries:
Configure::write('DaisyUi.classMapOverrides', ['badge.color.success' => 'badge-success custom']);
- A missing key throws
OutOfBoundsException— that includes invalid option values like['color' => 'nope']. - The per-call
classoption is appended to the map's classes. To replace a map class, override the map entry. - Class-map keys are public API: renaming or removing a key is a major release. Changing a default value is a minor release.
Tailwind utility classes the plugin emits
Almost every class the helpers output is a daisyUI class. A few features also need plain Tailwind utilities; they live in plugin-owned class-map keys, so you can override them like any other entry:
| Key | Default | Used by | If you remove it |
|---|---|---|---|
control.part.error |
label text-error |
Form->control() error message |
Errors lose their red color |
control.layout.horizontal |
grid-cols-[10rem_1fr] items-center gap-x-4 |
Form->create(…, ['align' => 'horizontal']) |
Horizontal forms stack vertically |
control.layout.offset |
col-start-2 |
help / hint / error text in horizontal forms | That text lands in the label column |
table.part.wrapper |
overflow-x-auto |
DataDisplay->table() scroll wrapper (wrap => false omits it) |
Wide tables overflow on small screens |
themeController.part.menu |
menu bg-base-200 rounded-box w-52 p-2 shadow-sm |
Actions->themeController() with 3+ themes (or pass menuClass) |
The theme dropdown has no background or width |
flash.part.dismissToggle |
peer sr-only |
the hidden checkbox behind a flash message's ✕ | The checkbox becomes visible / dismiss stops working |
flash.part.dismissible |
peer-checked:hidden peer-focus-visible:outline-2 |
the flash alert | ✕ no longer hides the message |
Things to know:
- CDN mode: nothing to do — the Tailwind browser build generates any class it finds on the page.
- Your own Tailwind build: these classes are written out literally in the
plugin's
config/class_maps/daisyui.php, which the@sourcelines in Production CSS already scan. If you override them in your app's config, keep the@source "../config";line so Tailwind sees your values too. - Overriding: replace a whole value, e.g.
Configure::write('DaisyUi.classMapOverrides', ['table.part.wrapper' => 'overflow-x-auto rounded-box border']). Keep the classes a feature depends on (e.g.peer/peer-checked:hiddenfor the flash dismiss) or that feature stops working.
CSS loading
AssetsHelper::css() emits pinned daisyUI/Tailwind CDN tags (SRI-hashed):
// templates/layout/default.php, inside <head> <?= $this->Assets->css() ?>
CDN mode is for development and prototyping only. Tailwind's browser build compiles CSS in every visitor's browser on every page load — it is not intended for production. For production, load a compiled stylesheet instead:
Configure::write('DaisyUi.cdn', false); // in your layout: <?= $this->Html->css('main') ?>
The CDN URLs are overridable via Configure::write('DaisyUi.cdn', [...]).
Each entry carries its own URL and integrity hash, so a hash is never
applied to the wrong file:
Configure::write('DaisyUi.cdn', [ 'daisyui' => ['url' => 'https://example.com/daisy.css'], 'tailwind' => [ 'url' => 'https://example.com/tw.js', 'integrity' => 'sha384-…', ], ]);
An entry without integrity (or with an empty one) is emitted without the
integrity/crossorigin attributes; other entries keep their defaults.
Production CSS: a Tailwind build
Recommended for PHP projects without Node: the Tailwind standalone CLI
(single binary) with daisyUI's daisyui.mjs plugin file, which daisyUI
officially supports.
Tailwind v4 skips gitignored paths such as vendor/, so register the
plugin's sources in your input CSS:
@import "tailwindcss"; @source "../vendor/themusicdev/cakephp-daisyui/src"; @source "../vendor/themusicdev/cakephp-daisyui/config"; @source "../vendor/themusicdev/cakephp-daisyui/templates"; @source "../config"; /* app class-map overrides */ @plugin "./daisyui.mjs";
Content-Security-Policy
Three parts of this plugin use inline script/attributes and need a CSP that
allows them (e.g. unsafe-inline or a nonce):
- the modal's inline
onclickhandler (showModal()), and - the theme-persistence script emitted by
Assets::css()(turn it off withDaisyUi.persistTheme => false), and - the
oninvalid/oninputhandlers CakePHP's FormHelper adds to required fields (turn them off with the helper configautoSetCustomValidity => false).