duanmorong9597 2012-07-01 19:42 采纳率: 100%
浏览 34
已采纳

为什么我不能从扩展AppController的类中访问CakeRequest对象?

Why does cakePHP complain that $request is undefined? I was following the tutorial that they have up on their site how to make a blog (the hello work of frameworks) and I had been fixing the various errors that i came across in the tutorial code (I figured the tutorial was a little bit out of date) but here is one I haven't been able to fathom. Looking at the api documentation it says that Controller has a $request property. my PostsController extends AppController which extends Controller, so it would make sense that it would have the $requests property, but it doesn't, not even according to print_r.

Here is my code (straight from the tutorial):

class PostsController extends AppController {
    public $helpers = array('Html', 'Form', 'Session');
    public $components = array('Session');
    ...

    public function add() {
        if ($this->request->is('post')) {
            ...
        }
    }
}

here is the error page:

Notice (8): Undefined property: PostsController::$request [APP/controllers/posts_controller.php, line 16]
Code

public function add() {
if ($this->request->is('post')) {

PostsController::add() - APP/controllers/posts_controller.php, line 16
Object::dispatchMethod() - CORE/cake/libs/object.php, line 116
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 227
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 194
[main] - APP/webroot/index.php, line 88
Fatal error: Call to a member function is() on a non-object in shared/THS/test/www/MyCake/app/controllers/posts_controller.php on line 16

Thanks for any help you can provide.

  • 写回答

1条回答 默认 最新

  • dqy13020940 2012-07-01 21:38
    关注

    According to the files paths that one can see in the error you get, you have not installed Cake 2.x but probably Cake 1.3.

    And if the tutorial you are following mentions the CakeRequest class, then you are following the Cake 2.x tutorial...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line