I've (somewhat) come to the conclusion that my application I'm currently developing has 3 'kinds' of actions.
1. A 'regular' action which executes some buisness logic and returns a view. Nothing special.
2. An action which only executes some buisness logic. This could for instance be the 'DeleteProductAction'.
3. An action which actually does neither. This could for instance be the 'AddProductAction'. When the action gets performed it only checks whether the user has submitted a valid form (valid productname, price, etc.). The action then forwards to either 'AddProductSuccessfullAction', which inserts the product in the DB, or 'AddProductFailureAction' which returns a 'FailureView'.
Code example:
It is kinda complicated to implement an actionChain since some action has views, some does not, and some doesn't even do anything (almost!). My 11th sense tells me that having 3 types of actions isn't gonna make my life easier.PHP Code:// Product controller
function &getAction($action)
{
switch($action)
{
case 'AddProduct': // Action of type 3
$validator = new Validator(new Request());
// Add rules, validate, etc
if ($validator->isValid())
{
// Perform the AddProductSuccess now instead.
$this->forward('AddProductSuccess');
}
else
{
// Perform the AddProductFailure now instead.
$this->forward('AddProductFailure');
}
case 'AddProductSuccess': // Action of type 1
return new AddProductSuccessAction();
case 'AddProductFailure':
return new AddProductFailureAction();
case 'ShowProduct':
return new ShowProductAction();
case 'DeleteProduct': // Action of type 2
// Delete the Product and then show the products by performing the ListProductsAction! (Need some kind of actionchain?)
return new DeleteProductAction();
case 'ModifyProduct':
$validator = new Validator(new Request());
// Add rules, validate, etc
if ($validator->isValid())
{
return new ModifyProductAction();
}
else
{
return new FailedModifyProductAction();
}
case 'ListProducts':
return new ListProductsAction();
}
}
Anyone has a solution to this?







Bookmarks