i working with model(shown below)......
use Phalcon\Mvc\Model;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator;
use Phalcon\Validation\Validator\PresenceOf as PresenceOfValidator;
class Employee extends Model
{
/*
*Id of the employee in db
*
*/
public $id;
/**
* Name of corporate employee
*/
public $name;
/**
* UserName of corporate employee
*/
public $user_name;
/**
* Mobile Number of corporate employee
*/
public $mdn;
/*
* delete
*/
public $delete;
public function initialize()
{
$this->setup(array(
'notNullValidations'=>false,
));
$this->setSource("employee");
$this->hasManyToMany('id', 'employee', 'employee_id', 'type_id', 'Type', 'id', array(
'alias' => 'type'
));
$this->hasManyToMany('id', 'EmployeeCorporateRelation', 'employee_id', 'corporate_id', 'Corporate', 'id', array(
'alias' => 'corporate'
));
}
public function validation()
{
$validator = new Validation();
$validator->add(
'name',
new PresenceOfValidator([
'message' => 'Name is required'
]));
$validator->add(
'user_name',
new PresenceOfValidator([
'message' => 'UserName is required'
]));
$validator->add(
'mdn',
new PresenceOfValidator([
'message' => 'Mobile number is required'
]));
$validator->add(
'user_name',
new UniquenessValidator([
'message' => 'Sorry, That username is already taken'
]));
$validator->add(
'mdn',
new UniquenessValidator([
'message' => 'Sorry, That mdn is already exists'
]));
return $this->validate($validator);
}
}
now even i have a form for this.... while displaying the data (.volt file) i want to display the alias data for the variables for which alias has set
{% for element in form %}
{% if is_a(element, 'Phalcon\Forms\Element\Hidden') %}
{{ element }}
{% else %}
<div class="form-group">
{{ element.label() }}
{{ element.render(['class': 'form-control']) }}
</div>
{% endif %}
{% endfor %}
for variables like corporate id i want to the show it's name rather than its id. How can i do it. Hope you understand my problem!!! Please help!!