PhalconPHP - 返回空数据的模型

时间:2016-08-09 11:35:55

标签: php mysql phalcon

最近,我一直在研究使用Phalcon PHP框架的系统。直到现在,它一帆风顺。

使用模型从MySQL数据库中提取数据时似乎遇到了问题。其他所有东西似乎都运行正常,但是有几个字段返回空数据,尽管MySQL表中的这些字段中有数据。

在扫描数据库本身之后,我似乎无法找到这些特定字段为空的原因,因为返回的类似字段的数据完整无缺。

我已经将模型数据插入到数组中,以便我更容易浏览它并找出发生了什么,结果就是这样:

[applications]    =>
    [application_id] => 5
    [application_user] => 1
    [application_servers] => skybuild
    [application_approved] => 
    [application_denied] => 
    [application_reviewed] => 
    [application_approvals] => 0
    [application_denials] => 0
    [application_date] => 1470739996
    [application_message] => This is just a test application to see whether the system is working.
[user]    =>
    [user_id] => 1
    [user_fname] => Leo
    [user_lname] => **********
    [user_birthday] => ****-**-**
    [user_email] => **********@**********.**.**
    [user_uname] => Leo_V117
    [user_upass] => ********************************
    [user_account] => ********-****-****-****-************
    [user_active] => Y
    [user_banned] => 
    [user_suspended] => 
    [user_registered] => 

有问题的字段是:

  • 应用
    • application_approved
    • application_denied
    • application_reviewed
  • 用户
    • user_banned
    • user_suspended
    • user_registered

问题是: 为什么这些特定字段会返回空数据,最终 HOW 可以修复它。

PHP代码

自举

<?php ########################
##############################

use Phalcon\Mvc\Application;

error_reporting(E_ALL);
try {

    /**
     * Define some useful constants
     */
    define('BASE_DIR', dirname(__DIR__));
    define('APP_DIR', BASE_DIR . '/app');

    \Phalcon\Mvc\Model::setup(array(
        'notNullValidations' => false
    ));

    /**
     * Read the configuration
     */
    $config = include APP_DIR . '/config/config.php';

    /**
     * Read auto-loader
     */
    include APP_DIR . '/config/loader.php';

    /**
     * Read services
     */
    include APP_DIR . '/config/services.php';

    /**
     * Handle the request
     */
    $application = new Application($di);
    echo $application->handle()->getContent();

} catch (Exception $e) {
    echo '<pre>';
    print_r ( $e->getMessage() );
    print_r ( nl2br( htmlentities( $e->getTraceAsString() ) ) );
    echo '</pre>';
}

##############################
########################### ?>

帐户

<?php ########################
##############################

namespace ProjectRogue\Models;

use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Uniqueness;

class Accounts extends Model {
    public $user_id;        // User ID

    public $user_fname;     // Field: First Name
    public $user_lname;     // Field: Last Name
    public $user_birthday;  // Field: Date of Birth
    public $user_email;     // Field: E-Mail
    public $user_uname;     // Field: Username
    public $user_upass;     // Field: Password
    public $user_account;   // Minecraft Account UUID

    public $user_active;    // Active
    public $user_banned;    // Banned
    public $user_suspended; // Suspended

    public $user_registered;

    public function beforeValidationOnCreate() {
        $this->user_active = 'N';
        $this->user_banned = 'N';
        $this->user_suspended = 'N';
        $this->user_code = $this->generateCode();
        $this->user_registered = time();
    }

    public function afterSave() {
        if( $this->user_active == 'N' ) {
            // Check E-Mail Status;
            $email = new EmailConfirmation();

            $email->email_user = $this->user_id;
            $email->email_code = $this->generateCode();
            $email->email_created = date("Y-m-d H:i:s", time());

            if( $email->save() ) {
                $this->getDI()->getFlash()->notice('A confirmation E-Mail has been sent to '.$this->user_email);
            }

            // Send Commands;
            $service_servers = new ServiceServers();
            $service_commands = array();

            $servers = $service_servers::find();

            $json_response['data']['servers_size'] = count($servers);

            foreach( $servers as $server ) {
                $service_commands[ $server->server_id ] = new ServiceCommands();

                // Insert Data;
                $service_commands[ $server->server_id ]->assign(array(
                    'command_server'        =>  $server->server_token,
                    'command_body'          =>  'broadcast &6&l[player]&r &fhas just registered an account to our website!',
                    'command_player'        =>  $this->user_account,
                    'command_player_online' =>  'Y'
                ));

                // Save;
                $service_commands[ $server->server_id ]->save();
            }
        }
    }

    public function validation() {
        $this->validate(new Uniqueness(array(
            'field'         => 'user_uname',
            'message'       => 'This Username is already in use.'
        )));

        $this->validate(new Uniqueness(array(
            'field'         => 'user_email',
            'message'       => 'This E-Mail is already in use.'
        )));

        $this->validate(new Uniqueness(array(
            'field'         => 'user_account',
            'message'       => 'This Minecraft Account is already in use.'
        )));

        return $this->validationHasFailed() != true;
    }
}

##############################
########################### ?>

ApplicationStaff

<?php ########################
##############################

namespace ProjectRogue\Models;

use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Uniqueness;

class ApplicationsStaff extends Model {
    public $application_id;         // Application ID;
    public $application_user;       // Application User;
    public $application_servers;    // Application Servers;
    public $application_approved;
    public $application_denied;
    public $application_reviewed;
    public $application_approvals;  // Application Approvals;
    public $application_denials;    // Application Denials;
    public $application_date;       // Application Date;
    public $application_message;    // Application Message;

    public function beforeValidationOnCreate() {
        $this->application_date = time();
        $this->application_approvals = 0;
        $this->application_denials = 0;

        $this->application_approved = "N";
        $this->application_denied = "N";
        $this->application_reviewed = "N";
    }

    public function validation() {
        return $this->validationHasFailed() != true;
    }
}

##############################
########################### ?>

1 个答案:

答案 0 :(得分:0)

事实证明,每个模型的数据都缓存在我的服务中。删除所述缓存会强制模型按预期返回数据。