【发布时间】:2010-12-19 08:56:38
【问题描述】:
我遇到了表单助手的问题。我的控制器名称是posts_controller.php,如下所示
<?php
Class PostsController extends AppController
{
var $name='Posts';
var $helpers=array('Html','Form','Link');
var $components = array('Session');
function index()
{
$this->pageTitle='Cake PHP Index page';
$this->paginate();
$this->set('posts',$this->Post->find('all'));
}
function view($id=null)
{
$this->Post->id = $id;
$this->set('post', $this->Post->read());
}
function add()
{
if(!empty ($this->data))
{
if($this->Post->save($this->data))
{
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
}
}
}
}
?>
当我转到添加操作时,视图 add.ctp 会加载相应的表单。
这是我的视图文件add.ctp
<?php
echo $this->Form->create('Post');
echo $this->input('title');
echo $this->input('body');
echo $this->Form->end('Save');
?>
当我提交表单时,我收到一条错误消息,指出您的控制器中未定义发布操作。当我在浏览器中检查页面的来源时,表单的操作有一个错误的值。我得到的值是
<form id="PostAddForm" method="post" action="/cakephp/app/webroot/index.php/posts/posts/add">
而不是
<form id="PostAddForm" method="post" action="/cakephp/app/webroot/index.php/posts/add">
你能帮帮我吗?
【问题讨论】:
标签: cakephp