Skip to content

Instantly share code, notes, and snippets.

@predominant
Created December 14, 2011 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save predominant/1475439 to your computer and use it in GitHub Desktop.
Save predominant/1475439 to your computer and use it in GitHub Desktop.
Automatic table creation for missing tables.
<?php
class AppModel extends Model {
/**
* Overridden setSource allows creation of table in the event a MissingTableException is raised.
*
* @param string $tablename Table name
* @return void
*/
public function setSource($tablename) {
try {
parent::setSource($tablename);
} catch (MissingTableException $e) {
$this->query($this->_createStatement);
parent::setSource($tablename);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment