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仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题