Changeset 107 for trunk/trax/vendor/trax/scaffold_controller.php
- Timestamp:
- 01/02/06 22:19:42 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/scaffold_controller.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/scaffold_controller.php
r106 r107 25 25 class ScaffoldController extends ActionController { 26 26 27 function __construct($model_name, $controller_name, $action = "index") { 28 if($action == "") { 29 $action = "index"; 30 } 31 $model_name = strtolower($model_name); 27 function __construct($model_name) { 28 $model_name = strtolower($model_name); 32 29 $this->model_name = Inflector::camelize($model_name); 30 $this->model_object_name = Inflector::singularize($model_name); 33 31 $this->model_class = Inflector::classify($model_name); 34 32 $this->model_name_plural = Inflector::humanize(Inflector::pluralize($model_name)); … … 37 35 $this->raise("Trying to use scaffolding on a non-existing Model ".$model_name, "Unknown Model", "404"); 38 36 } 39 $this->controller_name = $controller_name;40 37 } 41 38 … … 50 47 $model_class = $this->model_class; 51 48 $model = new $model_class(); 52 $this-> model= $model->find($_REQUEST['id']);49 $this->{$this->model_object_name} = $model->find($_REQUEST['id']); 53 50 } 54 51 55 52 function add() { 56 53 $model_class = $this->model_class; 57 $this-> model = new $model_class($_REQUEST['model']);54 $this->{$this->model_object_name} = new $model_class($_REQUEST[$this->model_object_name]); 58 55 if($_POST) { 59 if($this->model->save($_REQUEST['model'])) { 60 $_SESSION['flash']['notice'] = $this->model_name_human." was successfully created."; 61 $this->index(); 62 $this->render_action = "index"; 56 if($this->{$this->model_object_name}->save($_POST[$this->model_object_name])) { 57 Session::flash('notice', $this->model_name_human." was successfully created."); 58 $this->redirect_to = url_for(array(":action" => "index")); 63 59 } else { 64 $_SESSION['flash']['error'] = "Error adding ".$this->model_name_human." to the database.";60 Session::flash('error', "Error adding ".$this->model_name_human." to the database."); 65 61 } 66 62 } … … 70 66 $model_class = $this->model_class; 71 67 $model = new $model_class(); 72 $this->model = $model->find($_REQUEST['id']); 73 68 $this->{$this->model_object_name} = $model->find($_REQUEST['id']); 74 69 if($_POST) { 75 if($this-> model->save($_REQUEST['model'])) {70 if($this->{$this->model_object_name}->save($_POST[$this->model_object_name])) { 76 71 Session::flash('notice', $this->model_name_human." was successfully updated."); 77 $this->show(); 78 $this->render_action = "show"; 72 $this->redirect_to = url_for(array(":action" => "show", ":id" => $this->{$this->model_object_name})); 79 73 } else { 80 $_SESSION['flash']['error'] = "Error saving ".$this->model_name_human." to the database.";74 Session::flash('error', "Error saving ".$this->model_name_human." to the database."); 81 75 } 82 76 } … … 89 83 $model = $model->find($_REQUEST['id']); 90 84 if($model->delete()) { 91 $_SESSION['flash']['notice'] = $this->model_name_human." was successfully deleted.";85 Session::flash('notice', $this->model_name_human." was successfully deleted."); 92 86 } else { 93 $_SESSION['flash']['error'] = "Error deleting ".$this->model_name_human." from the database.";87 Session::flash('error', "Error deleting ".$this->model_name_human." from the database."); 94 88 } 95 89 } 96 $this->index(); 97 $this->render_action = "index"; 90 $this->redirect_to = url_for(array(":action" => "index")); 98 91 } 99 92
