My model looks like this: (adjust from vokuru sample)
<?php
use Phalcon\Mvc\Model;
class emailConfirmations extends Model
{
/**
*
* @var integer
*/
public $id;
/**
*
* @var integer
*/
public $usersId;
public $code;
/**
*
* @var integer
*/
public $createdAt;
/**
*
* @var integer
*/
public $modifiedAt;
public $confirmed;
/**
* Before create the user assign a password
*/
public function beforeValidationOnCreate()
{
// Timestamp the confirmaton
$this->createdAt = time();
// Generate a random confirmation code
$this->code = preg_replace('/[^a-zA-Z0-9]/', '', base64_encode(openssl_random_pseudo_bytes(24)));
// Set status to non-confirmed
$this->confirmed = 'N';
}
/**
* Sets the timestamp before update the confirmation
*/
public function beforeValidationOnUpdate()
{
// Timestamp the confirmaton
$this->modifiedAt = time();
}
/**
* Send a confirmation e-mail to the user after create the account
*/
public function afterCreate()
{
$this->getDI()
->getMail()
->send(array(
$this->user->email => $this->user->name
), "Please confirm your email", 'confirmation', array(
'confirmUrl' => '/confirm/' . $this->code . '/' . $this->user->email
));
}
public function initialize()
{
$this->belongsTo('usersId', 'MPXUsers', 'id', array(
'alias' => 'MPXUserPointer'
));
}
public function getSource()
{
return 'email_confirmations';
}
}
I have an Action in a controller for a different entity MPXUserController/sendMail:
$confirmation = new emailConfirmations();
Can I create a new entity like above in a controller of a different entity (MPXUser)?
my config.ini has the models dir:
[application]
controllersDir = app/controllers/
modelsDir = app/models/
viewsDir = app/views/
pluginsDir = app/plugins/
formsDir = app/forms/
libraryDir = app/library/
baseUri = /MPXMaster/