What I want to ask is,
let's say I have a class Info
and there's a getter in the info called getABC()
In a controller I assigned something like
$info = new Info();
$variable['info'] =$info;
and $variable
is being passed into the view.
In the view, am I able to use something like $variable['info']->getABC()
?
I know I can just test it out myself, and failed saying something like it did not exist and $variable['info']
does show something though.
I just want to make sure that $variable['info']->getABC()
is suppose to NOT work or it should but I am just doing something wrong that's why I couldn't get what's needed.
actual code below........
Class
class CreditCardPayment{
private $_card_type = '';
private $_card_number = '';
private $_card_number_last_4 = '';
public function setCardType($v)
{
$this->_card_type = $v;
return $this;
}
public function setCardNumber($v)
{
$this->_card_number = $v;
return $this;
}
public function setCardNumberLast4($v) {
$lastFourDigits = substr($v, -4);
$output = 'xxxx-xxxx-xxxx-' . $lastFourDigits;
$this->_card_number_last_4 = $output;
return $this;
}
public function getCardType() {
return $this->_card_type;
}
public function getCardNumber() {
return $this->_card_number;
}
public function getCardNumberLast4() {
return $this->_card_number_last_4;
}
}
and in Controller let's say when it's successful....it'll be something like this where $creditCardPayment = new CreditCardPayment
and I tried var_dump($creditCardPayment)
that definitely info is all filled and of course those are private
variables so I had to use the getter
retrieve them.
Controller
$ordermess['creditCardPaymentInfo'] = $creditCardPayment;
\Yii::$app->session->set('ordermess', $ordermess);
$this->redirect('/pay/completed');
then in my view...I did this as testing
<?php
echo '<pre>';
echo ($ordermess['creditCardPaymentInfo']->getCardNumberLast4());
echo '</pre>';
die;
?>
then when I load the page I would get error.
Call to a member function getCardNumberLast4() on a non-object