phalcon 我的用户创建表单不适用于我的数据库

phalcon my user creation form not working well with my database

我是 phalcon 的新手,我遇到了一个非常奇怪的问题,这里有一个更好的解释

form validation picture with var dump

database picture

这是我的控制器:

/**
 * Creates a new user
 */
public function createAction()
{
    if (!$this->request->isPost()) {
        $this->dispatcher->forward([
            'controller' => "users",
            'action' => 'index'
        ]);

        return;
    }

    $user = new Users();
    $user->setlastName($this->request->getPost("LastName"));
    $user->setfirstName($this->request->getPost("FirstName"));
    $user->setlogin($this->request->getPost("Login"));
    $user->setpassword($this->request->getPost("password"));
    $user->seteMail($this->request->getPost("eMail"));

    var_dump($this->request->getPost("LastName"));
    var_dump($this->request->getPost("FirstName"));
    var_dump($this->request->getPost("Login"));
    var_dump($this->request->getPost("Password"));
    var_dump($this->request->getPost("eMail"));

    var_dump($user);


    if (!$user->save()) {
        foreach ($user->getMessages() as $message) {
            $this->flash->error($message);
            var_dump($message);
        }

        $this->dispatcher->forward([
            'controller' => "users",
            'action' => 'new'
        ]);

        return;
    }

    $this->flash->success("user was created successfully");

    $this->dispatcher->forward([
        'controller' => "users",
        'action' => 'index'
    ]);
}

我的表格:

<?php
        echo $this->tag->form(
            [
                "users/create",
                "class" => "form-horizontal"
            ]
        );
    ?>

    <div class="form-group">
        <label for="fieldLastname" class="col-sm-2 control-label">LastName</label>
        <div class="col-sm-10">
            <?php echo $this->tag->textField(["LastName", "cols" => 30, "rows" => 4, "class" => "form-control", "id" => "fieldLastname"]) ?>
        </div>
    </div>

    <div class="form-group">
        <label for="fieldFirstname" class="col-sm-2 control-label">FirstName</label>
        <div class="col-sm-10">
            <?php echo $this->tag->textField(["FirstName", "cols" => 30, "rows" => 4, "class" => "form-control", "id" => "fieldFirstname"]) ?>
        </div>
    </div>

    <div class="form-group">
        <label for="fieldLogin" class="col-sm-2 control-label">Login</label>
        <div class="col-sm-10">
            <?php echo $this->tag->textField(["Login", "size" => 30, "class" => "form-control", "id" => "fieldLogin"]) ?>
        </div>
    </div>

    <div class="form-group">
        <label for="fieldPassword" class="col-sm-2 control-label">Password</label>
        <div class="col-sm-10">
            <?php echo $this->tag->passwordField(["Password", "size" => 30, "class" => "form-control", "id" => "fieldPassword"]) ?>
        </div>
    </div>

    <div class="form-group">
        <label for="fieldEmail" class="col-sm-2 control-label">EMail</label>
        <div class="col-sm-10">
            <?php echo $this->tag->textField(["eMail", "size" => 30, "class" => "form-control", "id" => "fieldEmail"]) ?>
        </div>
    </div>


    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <?php echo $this->tag->submitButton(["Save", "class" => "btn btn-default"]) ?>
        </div>
    </div>

    <?php echo $this->tag->endForm(); ?>

这里是用户 class :

<?php

namespace Phalcon_Punch;

class Users extends \Phalcon\Mvc\Model
{

/**
 *
 * @var integer
 */
protected $iD;

/**
 *
 * @var string
 */
protected $lastName;

/**
 *
 * @var string
 */
protected $firstName;

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

/**
 *
 * @var string
 */
protected $password;

/**
 *
 * @var string
 */
protected $grants;

/**
 *
 * @var string
 */
protected $status;

/**
 *
 * @var string
 */
protected $lastUpdateDate;

/**
 *
 * @var string
 */
protected $eMail;

/**
 *
 * @var string
 */
protected $tag;

/**
 * Method to set the value of field ID
 *
 * @param integer $iD
 * @return $this
 */
public function setID($iD)
{
    $this->iD = $iD;

    return $this;
}

/**
 * Method to set the value of field LastName
 *
 * @param string $lastName
 * @return $this
 */
public function setLastName($lastName)
{
    $this->lastName = $lastName;

    return $this;
}

/**
 * Method to set the value of field FirstName
 *
 * @param string $firstName
 * @return $this
 */
public function setFirstName($firstName)
{
    $this->firstName = $firstName;

    return $this;
}

/**
 * Method to set the value of field Login
 *
 * @param string $login
 * @return $this
 */
public function setLogin($login)
{
    $this->login = $login;

    return $this;
}

/**
 * Method to set the value of field Password
 *
 * @param string $password
 * @return $this
 */
public function setPassword($password)
{
    $this->password = $password;

    return $this;
}

/**
 * Method to set the value of field Grants
 *
 * @param string $grants
 * @return $this
 */
public function setGrants($grants)
{
    $this->grants = $grants;

    return $this;
}

/**
 * Method to set the value of field Status
 *
 * @param string $status
 * @return $this
 */
public function setStatus($status)
{
    $this->status = $status;

    return $this;
}

/**
 * Method to set the value of field LastUpdateDate
 *
 * @param string $lastUpdateDate
 * @return $this
 */
public function setLastUpdateDate($lastUpdateDate)
{
    $this->lastUpdateDate = $lastUpdateDate;

    return $this;
}

/**
 * Method to set the value of field eMail
 *
 * @param string $eMail
 * @return $this
 */
public function setEMail($eMail)
{
    $this->eMail = $eMail;

    return $this;
}

/**
 * Method to set the value of field tag
 *
 * @param string $tag
 * @return $this
 */
public function setTag($tag)
{
    $this->tag = $tag;

    return $this;
}

/**
 * Returns the value of field iD
 *
 * @return integer
 */
public function getID()
{
    return $this->iD;
}

/**
 * Returns the value of field lastName
 *
 * @return string
 */
public function getLastName()
{
    return $this->lastName;
}

/**
 * Returns the value of field firstName
 *
 * @return string
 */
public function getFirstName()
{
    return $this->firstName;
}

/**
 * Returns the value of field login
 *
 * @return string
 */
public function getLogin()
{
    return $this->login;
}

/**
 * Returns the value of field password
 *
 * @return string
 */
public function getPassword()
{
    return $this->password;
}

/**
 * Returns the value of field grants
 *
 * @return string
 */
public function getGrants()
{
    return $this->grants;
}

/**
 * Returns the value of field status
 *
 * @return string
 */
public function getStatus()
{
    return $this->status;
}

/**
 * Returns the value of field lastUpdateDate
 *
 * @return string
 */
public function getLastUpdateDate()
{
    return $this->lastUpdateDate;
}

/**
 * Returns the value of field eMail
 *
 * @return string
 */
public function getEMail()
{
    return $this->eMail;
}

/**
 * Returns the value of field tag
 *
 * @return string
 */
public function getTag()
{
    return $this->tag;
}

/**
 * Initialize method for model.
 */
public function initialize()
{
    $this->setSchema("basephalcon");
    $this->setSource("users");
}

/**
 * Returns table name mapped in the model.
 *
 * @return string
 */
public function getSource()
{
    return 'users';
}

/**
 * Allows to query a set of records that match the specified conditions
 *
 * @param mixed $parameters
 * @return Users[]|Users|\Phalcon\Mvc\Model\ResultSetInterface
 */
public static function find($parameters = null)
{
    return parent::find($parameters);
}

/**
 * Allows to query the first record that match the specified conditions
 *
 * @param mixed $parameters
 * @return Users|\Phalcon\Mvc\Model\ResultInterface
 */
public static function findFirst($parameters = null)
{
    return parent::findFirst($parameters);
}
}

问题似乎是在数据库中,例如"LastName" 作为数据库字段名称,但 "lastName" 作为 PHP 字段名称。您的框架似乎使用命名约定将 PHP 字段名称映射到数据库字段名称,并且此约定区分大小写。

因此您需要重命名数据库字段名称或 PHP 字段名称,以便它们完全匹配。

可以使用columnMap()建立table和模型

中名字的对应关系
 public function columnMap()
    {
        return array(
            'LastName' => 'lastName', 
        );
    }