We are building a PHP application based on the good old codeigniter framework, and we have run into problems with a massive chained action consisting of several model calls that together are part of a large transaction in a database.
We want to be able to carry out a list of actions and receive a report on the status of each of the functions, regardless of the result.
Our first initial idea was to use PHP5 exceptions, but since we also need status messages that do not violate script execution, this was our solution that we encountered.
This is a bit like this:
$sku = $this->addSku( $name ); if ($sku === false) { $status[] = 'Something gone terrible wrong'; $this->db->trans_rollback(); return $status; } $image= $this->addImage( $filename); if ($image=== false) { $error[] = 'Image could not be uploaded, check filesize'; $this->db->trans_rollback(); return $status; }
Our controller is as follows:
$var = $this->products->addProductGroup($array); if (is_array($var)) { foreach ($var as $error) { echo $error . '<br />'; } }
This is apparently a very fragile solution to do what we need, but it is not scalable, not efficient compared to pure PHP exceptions, for example.
Is this really how this stuff is usually handled in MVC-based applications?
Thanks!
UPDATE: We did a fair share of the search and found this PHP function: register_shutdown_function. Is this what we are looking for? I have no idea and I canβt make it work the way we want it ... Link: http://php.net/manual/de/function.register-shutdown-function.php
source share