douwen7331 2011-12-31 09:18
浏览 49
已采纳

Cake PHP:使用Form helper时出现未定义的错误

I'm new to cakePHP.I just tried to create a simple form with a text box and a submit button on view and display the text using post data on the controller.

My View Code :

<?php echo $form->create(null, array('action' => 'index'));?>
<fieldset><legend>Enter Your Name</legend><?php echo $form->input('name'); ?></fieldset>
<?php echo $form->end('Go');?> 

My controller code :

<?php
class UsersController extends AppController  {
        var $name = 'Users';
        var $uses = array();
        var $helpers = array('Html','Form');

        function index() {
                if ( !empty($this->data) ) {
                        echo $this->data['name'];
                        $this->autoRender = false;
                }
        }
}

?>

I'm receiving the error ,

Notice (8): Undefined variable: form [APP/View/Users/index.ctp, line 1]
Code Context

include - APP/View/Users/index.ctp, line 1
View::_render() - CORE/Cake/View/View.php, line 598
View::render() - CORE/Cake/View/View.php, line 365
Controller::render() - CORE/Cake/Controller/Controller.php, line 900
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 114
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 89
[main] - APP/webroot/index.php, line 96

What is the problem in this.

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • duanjia6959 2011-12-31 09:30
    关注

    $form->method is from old versions of CakePHP. In new versions the form helpers are $this->Form->method. So, just replace those instances in your code:

    <?php echo $this->Form->create(null, array('action' => 'index'));?>
    <fieldset><legend>Enter Your Name</legend><?php echo $this->Form->input('name'); ?></fieldset>
    <?php echo $this->Form->end('Go');?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作