-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

私のコードに何か問題がありますか、それとも View ファイルを変更する必要がありますか?

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 に答える