I've been putting together a very basic MVC pattern for my admin interface. I'm sure it doesn't match up to most implementations, and that there are horrifying design errors, but it does what I want and seems to work very well. It's certainly made my coding process for new pages much simpler.
I have a question about handling errors. If the controller detects a $_POST['action'] key, it runs the method in the model which corresponds to that action. If at any stage of the model's method an error is generated, I need to return the error to the controller so the controller can generate a user error and halt the process.
At the moment, I have lines like this in the controller:
Code: Select all
if (FALSE === $conf = $this->_model->get_conf()) $this->make_user_error('Bad or missing configuration file. Please re-enter your settings.', 'install', 'conf');
if (TRUE !== $message = $this->_model->connect_configured_db($conf)) $this->make_user_error($message, 'install', 'conf');
if (TRUE !== $message = $this->_model->install_database_tables()) $this->make_user_error($message, 'install', 'conf');
if (TRUE !== $message = $this->_model->populate_db()) $this->make_user_error($message, 'install', 'conf');Code: Select all
function make_user_error($msg, $module = 'index', $page = NULL)Code: Select all
if (TRUE !== $message = ........ $this->make_user_error(all the time.
Any suggestions?