dongpai6567 2014-12-03 10:47
浏览 41
已采纳

获取通知(8):CakePHP 1.2.5中的未定义属性错误

I have no idea why I should get the above error. Also, in the same line, I'm getting the dreadful Fatal error: Call to a member function query() on a non-object error.

I have a controller home_loan_installment_repayment_controller.php, which has an index and view method.

class HomeLoanInstallmentRepaymentController extends AppController {

    function index() {
        //some work done here
    }

    function view() {
        //some work done here
    }
}

In the view page index.ctp of this controller, I'm calling another controller home_loan_installment_repayment_details_controller.php, which also has index() and view() methods. Something like this:

<td class="actions">
     <?php echo $html->link(__('View', true), array('action' => 'view', 'branch_id' => $branch_id, 'date' => $info[$i]['HomeLoanInstallmentRepayments']['REPAYMENT_DATE'])); ?>
      <a href="/sdb/HomeLoanInstallmentRepayment/edit/2014-11-25/branch_id:18">Edit</a>
      <a onclick="return confirm('Are you sure you want to delete # 2014-11-25?');" href="/sdb/HomeLoanInstallmentRepayment/delete/2014-11-25/branch_id:18">Delete</a>
      <!--The following link will navigate to a different controller-->
      <a href="/sdf-mis/HomeLoanInstallmentRepaymentDetails/index/branch_id:18">Installment Details</a>
</td>

In my home_loan_installment_repayment_details_controller.php controller, the following thing is done:

class HomeLoanInstallmentRepaymentDetailsController extends AppController {

        function index() {
            //In the following line, I'm getting the two errors
             $info = $this->HomeLoanInstallmentRepaymentDetails->query("SOME SQL QUERY");
             echo "<pre>";
             print_r($info);
             die();
        }

        function view() {
            //some work done here
        }
    }

After I $print_r($info), I get the errors:

Notice (8): Undefined property: HomeLoanInstallmentRepaymentDetailsController::$HomeLoanInstallmentRepaymentDetails [APP\controllers\home_loan_installment_repayment_details_controller.php, line 5

Fatal error: Call to a member function query() on a non-object in C:\wamp\www\sdb\app\controllers\home_loan_installment_repayment_details_controller.php on line 5

Note that I don't have any models for the above two controllers and I bypassed using models.

  • 写回答

1条回答 默认 最新

  • dongsun2789 2014-12-03 10:52
    关注

    You are calling the method with the controller's instance.You must have a model to do operation on the data.query() is a method of model so define the model. Try with the model name -

    $info = $this-><your model name>->query("SOME SQL QUERY");
    

    If you model is - HomeLoanInstallmentRepaymentDetail then try -

    $info = $this->HomeLoanInstallmentRepaymentDetail->query("SOME SQL QUERY");
    

    Or if you dont want to define the model then -

    ClassRegistry::init('AppModel')->query('Your query');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错