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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码