-1

嗨,我在我的 cakephp 中编写了以下代码。

<?php
    //Posts is the name of my View folder, add, edit arethe pages in Posts folder.
echo $this->Posts('add_or_edit');
?>
<fieldset>
<legend>
<?php  _('Add a Post'); ?>
</legend>
Please fill in all the fields.
<?php
echo $form->create('Post');
echo $form->error('Post.title');
echo $form->input('Post.title',array('id'=>'posttitle','label'=>'title','size'=>'50','maxlength'=>'255','error'=>false));
echo $form->error('Post.content');
echo $form->input('Post.content',array('id'=>'postcontent','type'=>'textarea','label'=>'Content:','rows'=>'10','error'=>false));
echo $form->end(array('label'=>'Submit Post'));
?>
</fieldset>

好吧,每当我尝试显示上面的代码时,我都会收到这样的错误

 Call to undefined method View::Posts() in C:\wamp\www\cake_php\app\View\Posts\add.ctp on line 2

我的代码有问题还是我需要更改我的视图文件?

4

1 回答 1

3

我希望这对你有用......你错过了 $this

        <fieldset>
        <legend>
        <h2> Add a Post Here </h2>
        </legend>
        Please fill in all the fields.
        <?php
        echo $this->form->create('Post');
        echo $this->form->error('Post.title');
        echo $this->form->input('Post.title',array('id'=>'posttitle','label'=>'title','size'=>'50','maxlength'=>'255','error'=>false));
        echo $this->form->error('Post.content');
        echo $this->form->input('Post.content',array('id'=>'postcontent','type'=>'textarea','label'=>'Content:','rows'=>'10','error'=>false));
        echo $this->form->end(array('label'=>'Submit Post'));
        ?>
        </fieldset>
于 2013-01-18T10:37:52.607 回答