[eluser]andyy[/eluser]
If one was writing an application that has all the functions broken down into class methods and you need to run some logic: if, else, etc - should you have the methods returning bool values and create the logic inside of the model, or should you have the class/method run the logic returning the result? It's hard to explain, hopefully that makes sense. Maybe an example to help:
How I was thinking it should work..
Code:
/**
* This would be the model
*
*/
$z = new Payments();
$z->method = 'credit_card';
$z->cardNumber = 1111222233334444;
$z->cardExpiry = 0114;
$result = $z->chargeCard();
if($result['status'] == 'success')
{
echo $result['message'];
// more logic pertaining to a successful payment..
}
else
{
echo $result['message'];
// more logic pertaining to an failed payment..
}
But I've also thought about this..
Code:
/**
* This would be the model
*
*/
$z = new Payments();
$z->method = 'credit_card';
$z->cardNumber = 1111222233334444;
$z->cardExpiry = 0114;
$z->chargeCard();
/**
* This would be the Payments class
*
*/
public function chargeCard()
{
// Logic to charge the credit card here...
// ......................................
// ......................................
if($result_of_transaction == false)
{
echo 'Payment failed';
// more logic pertaining to an failed payment..
}
else
{
echo 'Payment complete';
// more logic pertaining to an successful payment..
}
}
I've been thinking that any method's result should be determined within the model. If there is anything more than a bool value that needs to be returned, use an array and use the arrays values within the model.
Thoughts?