Issue
I've recently been using the controller to pass in a couple of values into my view. In my controller this is what it looks like when I pass in values from the controller to the view.
public function actionProcessPayment($id)
{
// if the account id was passed in
if(isset($_POST['listF']))
{
$account_id = $_POST['listF'];
// total due before payment
$totaldue = Recipient::model()->totaldue($id);
$result = Recipient::model()->MakePayment($id, $account_id);
if($result == 'not enough money')
{
Yii::app()->user->setFlash('not enough money', "This account does not have enough money
to make that transaction!");
$this->redirect(array('recipient/index', 'id' => $id));
}
else
$this->render('paysummary',array(
'id'=>$id,
'totaldue'=>$totaldue,
'numpeople'=>Paylist::model()->NumIndv($id),
'user_id'=>Login::model()->getUserId(),
'accountname'=>Account::model()->AccountName($account_id),
'accountbalance'=>Account::model()->AccountBalance($account_id),
''
));
}
Now, in order to get the account name (for example), I've created a function in the model called AccountName that takes in the account id as a parameter.
Like so
public function AccountName($id)
{
$model = Account::model()->findByPk($id);
return $name = $model->name;
}
This is working fine, but I feel like I am programming in a very roundabout way. Is there a way to change this to be one line of code? Is this how it should be called in the controller?
Solution
public function actionProcessPayment($id)
{
// if the account id was passed in
if(isset($_POST['listF']))
{
$account_id = $_POST['listF'];
// total due before payment
$totaldue = Recipient::model()->totaldue($id);
$result = Recipient::model()->MakePayment($id, $account_id);
$model = Account::model()->findByPk( $account_id );// <<---
if($result == 'not enough money')
{
Yii::app()->user->setFlash('not enough money', "This account does not have enough money
to make that transaction!");
$this->redirect(array('recipient/index', 'id' => $id));
}
else
$this->render('paysummary',array(
'id'=>$id,
'totaldue'=>$totaldue,
'numpeople'=>Paylist::model()->NumIndv($id),
'user_id'=>Login::model()->getUserId(),
'accountname'=>$model->name,// <<---
'accountbalance'=>$model->balance, // <<---
''
));
}
Answered By - Developerium
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.