I like having a base model for my models. I also couldn't find a method to generate an error list as a string or dom so I placed them in here, it's quite nice to use. If anyone has done anything else with models that are handy to you post them!
<?php
class BaseModel extends \Phalcon\Mvc\Model
{
use Timestamp;
// --------------------------------------------------------------
/**
* 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
// --------------------------------------------------------------