我是phalcon的新手,我遇到了一个很奇怪的问题,这是一个更好的解释
form validation picture with var dump
这是我的控制器:
/**
* 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(); ?>
这是Users类:
<?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);
}
}
答案 0 :(得分:0)
问题似乎出在数据库中,例如“ LastName”作为数据库字段名称,而“ lastName”作为PHP字段名称。看来您的框架使用命名约定将PHP字段名映射到数据库字段名,并且此约定区分大小写。
因此,您需要重命名数据库字段名称或PHP字段名称,以使其完全匹配。
答案 1 :(得分:0)
您可以使用columnMap()在表和模型中的名称之间建立对应关系
'Function to import Outlook contacts according to their client code
Sub ExportOutlookAddressBook()
Application.ScreenUpdating = False
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olAL As Outlook.AddressList
Dim olEntry As Outlook.AddressEntry
Dim CodeClient As String
Dim RCompanyName As String
Dim i As Integer
Dim AccountCount As Integer
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
CodeClient = 0
RCompanyName = 0
i = 0
AccountCount = olNS.Accounts.Count
Range("AA6:AF10").ClearContents
For i = 1 To AccountCount
Set olAL = olNS.AddressLists(i) 'Change name if different contacts list name
Set olEntry = olAL.AddressEntries(1)
ActiveWorkbook.ActiveSheet.Range("K6").Select
CodeClient = ActiveCell.Value
ActiveWorkbook.ActiveSheet.Range("AA6").Select
For Each olEntry In olAL.AddressEntries
' your looping code here
RCompanyName = Left(Right(olEntry.GetContact.CompanyName, 7), 6)
If RCompanyName = CodeClient Then
ActiveCell.Value = olEntry.GetContact.FullName
ActiveCell.Offset(0, 1).Value = olEntry.GetContact.BusinessTelephoneNumber 'business phone number
ActiveCell.Offset(0, 2).Value = olEntry.Address 'email address
ActiveCell.Offset(0, 3).Value = olEntry.GetContact.CompanyName
ActiveCell.Offset(0, 4).Value = olEntry.GetContact.BusinessAddress
ActiveCell.Offset(1, 0).Select
End If
Next olEntry
Next i
Set olApp = Nothing
Set olNS = Nothing
Set olAL = Nothing
Application.ScreenUpdating = True
ActiveWorkbook.ActiveSheet.Range("K7").Select
End Sub