Reputation: 1316
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.
Upvotes: 0
Views: 1244
Reputation: 31739
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');
Upvotes: 1