问题描述
当我更新我的表单时,我得到这个错误
500 |内部服务器错误| Doctrine_Connection_Mysql_Exception
when i am update my form, i got this error500 | Internal Server Error | Doctrine_Connection_Mysql_Exception
executeEdit
executeEdit
public function executeEdit(sfWebRequest $request)
{
$this->form = new ContactForm();
$this->rs = Doctrine::getTable('login')-> find($request->getParameter('id'));
$id=$request->getParameter('id');
$unm=$this->rs['username'];
$msg=$this->rs['message'];
$em=$this->rs['email'];
$sub=$this->rs['subject'];
$this->form->setDefault('id', $id);
$this->form->setDefault('username', $unm);
$this->form->setDefault('message', $msg);
$this->form->setDefault('email', $em);
$this->form->setDefault('subject', $sub);
//$this->forward404Unless($this->rs);
if ($request->isMethod('post'))
{
$this->form->bind($request->getParameter('contact'), $request->getFiles('contact'));
if ($this->form->isValid())
{
$name="'".$this->form->getValue('username')."'";
$message="'".$this->form->getValue('message')."'";
$email="'".$this->form->getValue('email')."'";
$sub="'".$this->form->getValue('subject')."'";
$id=$this->form->getValue('id');
$file = $this->form->getValue('doc');
$filename = sha1($unm).'_'.sha1($file->getOriginalName());
$extension = $file->getExtension($file->getOriginalExtension());
$path=sfConfig::get('sf_upload_dir').'/'.$filename.$extension;
$qs= Doctrine_Query::create()
->update('login l')
->set('l.username', $name)
->set('l.message', $message)
->set('l.email', $email)
->set('l.subject', $sub)
->set('l.doc', $path)
->where('l.id=?',$id)
->execute();
$this->redirect('user/show?id=' . $id);
}
}
}
这是我的编辑动作代码。所以什么是exaclty错误。我的错误是
,我该怎么办来解决这个错误?
请帮助我
this is my edit action code. so whats the exaclty error. and what is my mistakeand what can i do to solve this error?please help me
推荐答案
为什么要为要保存的值添加引号?教义会为你处理这个问题。尝试删除此部分:
Why do you add quotes to the values you are saving? Doctrine will handle this for you. Try removing this part:
$name="'".$this->form->getValue('username')."'";
$message="'".$this->form->getValue('message')."'";
$email="'".$this->form->getValue('email')."'";
$sub="'".$this->form->getValue('subject')."'";
您没有充分利用教义的功能,并充分体现。
You're not utilising the power of Doctrine and forms fully.
例如而不是这样:
$this->form = new ContactForm();
$this->rs = Doctrine::getTable('login')-> find($request->getParameter('id'));
$id=$request->getParameter('id');
$unm=$this->rs['username'];
$msg=$this->rs['message'];
$em=$this->rs['email'];
$sub=$this->rs['subject'];
$this->form->setDefault('id', $id);
$this->form->setDefault('username', $unm);
$this->form->setDefault('message', $msg);
$this->form->setDefault('email', $em);
$this->form->setDefault('subject', $sub);
您可以使用这个:
$this->rs = Doctrine_Core::getTable('login')-> find($request->getParameter('id'));
$this->form = new ContactForm($this->rs);
您只需通过添加此功能将表单连接到适当的模型:
You only have to "connect" your form to a proper model by adding this function:
public function getModelName()
{
return 'login';
}
然后您可以使用 save
方法,以便它自动保存您的对象,而无需创建更新查询。
You could then use the save
method on the form so it automatically saves your object without having to create the update query.
还可以看看 sfValidatorFile
,因为它会自动为您创建一个唯一的文件名。
Also have a look at the sfValidatorFile
as it will automatically create a unique filename for you.
这篇关于我有这个错误500 |内部服务器错误| Doctrine_Connection_Mysql_Exception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!