Skip to content

Instantly share code, notes, and snippets.

@rochamarcelo
Last active August 29, 2015 14:21
Show Gist options
  • Save rochamarcelo/38a4352a08f844bb98dd to your computer and use it in GitHub Desktop.
Save rochamarcelo/38a4352a08f844bb98dd to your computer and use it in GitHub Desktop.
Job
<?php
$this->Form->input(
'status',
['options' => $statuses]
);
echo $this->Statuses->getStatusText($entity['Job']['status']);
<?php
class Job extends AppModel
{
public function getStatuses()
{
return [
1 => 'Aberta(o)',
2 => 'Fechada(o)',
3 => 'Cancelada(o)'
];
}
}
<?php
class JobController extends AppController
{
public function add()
{
$statuses = $this->Job->getStatuses();
$this->set('statuses', $statuses);
}
}
<?php
class StatusesHelper extends Helper
{
private $statuses = [
1 => 'Aberta(o)',
2 => 'Fechada(o)',
3 => 'Cancelada(o)'
];
public function __construct(View $View, $settings = array()) {
parent::__construct($View, $settings);
$statuses = $View->get('statuses');
if ( !empty($statuses) ) {
$this->statuses = $statuses;
}
}
public function getStatuses()
{
return $this->statuses;
}
public function getStatusText($statusCode)
{
if ( isset($this->statuses[$statusCode]) ) {
return $this->statuses[$statusCode];
}
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment