Hi. I've just started learning Phalcon and I really like the framework and the documentation. One thing I have trouble doing (same with all the frameworks I try) is handling use cases like the following:
Create a new order: The first step is to select the customer from a table, but if the customer doesn't exist, it must be created (and saved to db) without breaking the work flow.
I can't tell the users "just exit the create order page, go to the customer page, create the customer, then come back and start creating the order again".
At the moment I use my own framework and do something like this (simplified):
class OrdersController {
public static function createOrder()
{
$customer = CustomersContrller::getCustomer();
// display new order form with customer details filled in...
}
}
class CustomersContrller {
public static function getCustomer()
{
if (isset($_GET['customer_id'])) {
return CustomersModel::findFirst($_GET['customer_id']);
} elseif (isset($_GET['new_customer'])) {
return self::createCustomer();
} else {
// display list of customers to click on
}
}
public static function createCustomer()
{
if (isset($_POST['new_customer'])) {
// save to db and return newly created record
} else {
// display the new customer form
// NOTE: the program exits after sending the form,
// so we won't return to the calling function from
// inside this 'else' block.
}
}
}
Can anyone recommend a way to do this in Phalcon? (I'm thinking some special routing might do it) Thanks
(I also asked this question at StackOverflow)