【发布时间】:2014-02-18 12:18:18
【问题描述】:
我的问题很小,但我没有找到解决方案。我将教义与 Zend Framework 2 一起使用,当我将数据刷新到要重定向到 blog 路由的数据库时,就会出现问题。它不工作。
这是我的行动:
public function addAction()
{
if ($this->request->isPost())
{
$article = new Article();
$article->setTitle($this->getRequest()->getPost('title'));
$article->setDate(new \DateTime());
$article->setContent($this->getRequest()->getPost('content'));
$article->setPublication($this->getRequest()->getPost('publication'));
$this->getObjectManager()->persist($article);
$this->getObjectManager()->flush();
$newId = $article->getId();
return $this->redirect()->toRoute('blog');
}
return new ViewModel();
}
这是我的观点:
<form class="contact_form" method="post" >
<ul>
<li>
<h2>Add Article</h2>
<span class="required_notification">* Required Field</span>
</li>
<li>
<label>Publication:</label>
<input type="checkbox" name="publication" required />
</li>
<li>
<label>Title:</label>
<input type="text" name="title" required />
</li>
<li>
<label>Date:</label>
<input type="date" name="date" name="date" required />
</li>
<li>
<label>Content:</label>
<textarea name="content" cols="40" rows="6" required ></textarea>
</li>
<li>
<button class="submit" type="submit">Add</button>
</li>
</ul>
</form>
最后这是我的路线:
'add' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/blog/article/add',
'defaults' => array(
'controller' => 'Application\Controller\Blog',
'action' => 'add',
),
),
),
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Blog',
'action' => 'add',
),
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/blog/add' => __DIR__ . '/../view/application/blog/add.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
当我按下添加按钮时,数据会正确添加到数据库中,但不会重定向到我的博客路由。这是我得到的图像:
【问题讨论】:
-
你的网络服务器还在运行吗?检查路由是否存在。请参考 ZF2 文档。您的代码非常不安全。
-
是的,我是 zend 的初学者,代码不安全?到底在哪里!!是的,网络服务器运行良好
-
@Mohammadov:: Sam 是对的,表单验证在哪里?记住一件事,
Never trust User Input!!
标签: php doctrine-orm doctrine zend-framework2