0

I am learning phalcon. I have some problems with models. Function FindFirst returns nothing, also it doesn't show any errors or exceptions. Here is my code:

public function indexAction()
{
    $user = Users::findFirst(1);
    var_dump($user);
}

And all what I get - is empty page.

Here is my Users Model:

<?php

namespace Models\User;

use Phalcon\Mvc\Model\Validator\Email as Email;

class Users extends \Phalcon\Mvc\Model
{

    /**
     *
     * @var integer
     */
    public $id;

    /**
     *
     * @var string
     */
    public $login;

    /**
     *
     * @var string
     */
    public $email;

    public function initialize()
    {
        $this->setSource("users");
    }

    /**
     * Validations and business logic
     */
    public function validation()
    {

        $this->validate(
            new Email(
                array(
                    'field'    => 'email',
                    'required' => true,
                )
            )
        );
        if ($this->validationHasFailed() == true) {
            return false;
        }
    }

    /**
     * Independent Column Mapping.
     * Keys are the real names in the table and the values their names in the application
     *
     * @return array
     */
    public function columnMap()
    {
        return array(
            'id' => 'id', 
            'login' => 'login', 
            'email' => 'email'
        );
    }

}

Some additional information: I have edited config files. Phalcon version is 2.0

TobyLL
  • 2,098
  • 2
  • 17
  • 23

1 Answers1

0

First you should ensure that the User model you are trying to load is in the right namespace, what means in your case you should use:

$user = \Models\User\Users::findFirst(1);

And to retrieve an output (depending on your index.php but probably this way) you should return "something", otherwise the buffer will be empty and nothing will be displayed.

ragnar
  • 1,252
  • 11
  • 18