简体   繁体   English

Phalcon ORM不起作用

[英]Phalcon ORM doesn't work

I am learning phalcon. 我正在学习phalcon。 I have some problems with models. 我的模型有些问题。 Function FindFirst returns nothing, also it doesn't show any errors or exceptions. 函数FindFirst不返回任何内容,也不会显示任何错误或异常。 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 Phalcon版本是2.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. 并要检索输出(取决于index.php,但可能以这种方式),您应该返回“ something”,否则缓冲区将为空并且不显示任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM