Skip to content

Commit

Permalink
More enum examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 25, 2023
1 parent cc681e3 commit 67b61c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions plugins/Sandbox/src/Model/Enum/UserStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

use Cake\Database\Type\EnumLabelInterface;
use Cake\Utility\Inflector;
use Tools\Model\Enum\EnumOptionsTrait;

enum UserStatus: int implements EnumLabelInterface
{
use EnumOptionsTrait;

case INACTIVE = 0;
case ACTIVE = 1;
case DELETED = 2;

/**
* @return string
Expand Down
9 changes: 9 additions & 0 deletions plugins/Sandbox/templates/CakeExamples/enums.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public function initialize(array \$config): void {

<br>

<h4>Manuel form (without entity passed in)</h4>

<?php echo $this->Form->create(); ?>
<?php echo $this->Form->control('status', ['options' => \Sandbox\Model\Enum\UserStatus::options([\Sandbox\Model\Enum\UserStatus::DELETED, \Sandbox\Model\Enum\UserStatus::ACTIVE])]); ?>
<?php echo $this->Form->submit(); ?>
<?php echo $this->Form->end(); ?>

<p>Note the order customization, as well.</p>

<h3>Serialization</h3>
<p>
When serializing, the actual (DB) value (in this case int) is used:
Expand Down

0 comments on commit 67b61c5

Please sign in to comment.