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

时间:2014-12-03 10:47:10

标签: php cakephp

我不知道为什么我应该得到上述错误。而且,在同一行,我得到了可怕的 Fatal error: Call to a member function query() on a non-object错误。

我有一个控制器home_loan_installment_repayment_controller.php,它有indexview方法。

class HomeLoanInstallmentRepaymentController extends AppController {

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

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

在此控制器的视图页面index.ctp中,我正在调用另一个控制器home_loan_installment_repayment_details_controller.php,它还具有index()和view()方法。像这样:

<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>

在我的home_loan_installment_repayment_details_controller.php控制器中,完成了以下操作:

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
        }
    }

在I $ print_r($ info)之后,我收到错误:

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

请注意,我没有上述两个控制器的任何型号,我绕过了使用模型。

1 个答案:

答案 0 :(得分:1)

您正在使用控制器实例调用该方法。您必须有一个模型来对数据进行操作。query()是一种模型方法,因此定义模型。尝试使用型号名称 -

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

如果您的模型是 - HomeLoanInstallmentRepaymentDetail,那么请尝试 -

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

或者,如果您不想定义模型,那么 -

ClassRegistry::init('AppModel')->query('Your query');