rendered paste body <sandbox>
<crud>
<routes>
<route name=".add" pattern="^/add$" action="Add" callback="AddCallback" />
<route name=".edit" pattern="^/edit/(id:\d+)$" action="Edit" />
<route name=".manage" pattern="^/manage$" action="Manage" />
<route name=".delete" pattern="^/delete/(id:\d+)$" action="Delete" />
</routes>
</crud>
</sandbox>
<route name=".products" pattern="^/products" module="Products">
<routes>
<xi:include xpointer="xpointer(/configurations/sandbox/crud/routes/route)" />
</routes>
</route>
<route name=".promotions" pattern="^/promotions" module="Promotions">
<routes>
<xi:include xpointer="xpointer(/configurations/sandbox/crud/routes/route)" />
</routes>
</route>
class AddCallback extends AgaviRoutingCallback
{
public function onMatched(array &$parameters, AgaviExecutionContainer $container)
{
# 1. find out Model we are dealing with, eg. Products/Promotions
$model = new Products;
try {
$model->add($parameters['form']);
$this->flash("Added {$model}!");
$return = 'Success';
} catch(Exception $e) {
$return = 'Error';
$this->flash($e->getMessage());
}
# 2. further processing:
if(file $model."Action" exists)
goto Action # more custom Add logic for this model
elseif(file $model.$return."View" exists)
goto View # more custom View logic for this model
else
goto $return."Template"
return true;
}
}