class not found issue

Hi to all

I am trying to incorporate the email sending examples into my project. I added an EmailConfirmations model, and anytime i try to access it from a controller...i get the class not found message.

$confirm = new EmailConfirmations();

Please provide more details. Model and Controller code, config with Model directory (Is it set correctly?).



5.8k

do you use namespace? If yes it better follow PSR-4 standard so you can autoload all of your project file with simple command



1.2k
edited Nov '14

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/


5.8k

try this

$confirmation = new \emailConfirmations();

you controller namespaced?

Basically if you autoload all your file you could use it anywhere.



1.2k
edited Nov '14

No...it is not name spaced