I am having a problem trying to pass a variable from the controller to the view. I think I am doing a mistake somewhere, I can't find it since I am new to it.
My controller Method is :
public function paymentdetail($order_code)
{
$this->load->model('Payment_Model');
$paymentDetail = $this->Payment_Model->getpaymentdetail($order_code);
$orderDetail = $this->Payment_Model->getOrderDetail($order_code);
// echo print_r($paymentDetail);
$datas['content'] = $this->load->view('payment/paymentDetail',
array('paymentDetail' => $paymentDetail,
'orderDetail' => $orderDetail), true);
$this->load->view('layouts/main_template', $datas);
}
The following model function getpaymentdetail() returns an array (result_array()) and this is the one I am concerned about. If I can work this one out then I can also work with other model methods.
$this->Payment_Model->getpaymentdetail($order_code);
When I type <?php echo $paymentDetail['column_name']; ?> in view file(PaymentDetail.php) I get an error
Undefined index: column_name
Why do I get this error?
$paymentDetail['column_name']does not exist. We can't help you, because we don't know what$this->Payment_Model->getpaymentdetail($order_code)returns. It's apparently not what you expect though.$this->Payment_Model->getpaymentdetail($order_code)returns an array like the functionresult_array(). I get values from the controller to view if I useecho print_r($paymentDetail);. I get the full array with value. But $paymentDetail['column_name'] is giving error that probably means I am doing something wrong that I don't know.$paymentDetail, putdie("<pre>".print_r($paymentDetail, true)."</pre>");Run your script again and update your question with what that variable contains.$paymentDetail['column_name']