Trait Example
<?php
class BaseModel extends \Phalcon\Mvc\Model
{
use Timestamp;
// --------------------------------------------------------------
public function onConstruct()
{
$this->di = \Phalcon\DI\FactoryDefault::getDefault();
}
// --------------------------------------------------------------
/**
* Returns a list of errors
*
* @return boolean|string
*/
public function getMessagesString()
{
if ($this->getMessages()) {
return implode(', ', $this->getMessages());
}
return false;
}
// --------------------------------------------------------------
/**
* Returns a HTML formatted list of errors
*
* @return boolean|string
*/
public function getMessagesList()
{
if (!$this->getMessages()) {
return false;
}
$output = '<ul>';
foreach ($this->getMessages() as $message) {
$output .= sprintf('<li>%s</li>', $message);
}
$output .= '</ul>';
return $output;
}
// --------------------------------------------------------------
}
trait TimeStamp
{
// --------------------------------------------------------------
public function beforeCreate()
{
$this->created_at = date('Y-m-d H:i:s');
}
// --------------------------------------------------------------
public function beforeUpdate()
{
$this->updated_at = date('Y-m-d H:i:s');
}
// --------------------------------------------------------------
}
// End of File
// --------------------------------------------------------------