Changeset 106 for trunk/trax/vendor/trax/scaffold_controller.php
- Timestamp:
- 01/01/06 21:37:32 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/scaffold_controller.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/scaffold_controller.php
r72 r106 25 25 class ScaffoldController extends ActionController { 26 26 27 function __construct($model_name, $controller_name, $action = "index") { 27 function __construct($model_name, $controller_name, $action = "index") { 28 28 if($action == "") { 29 29 $action = "index"; … … 33 33 $this->model_class = Inflector::classify($model_name); 34 34 $this->model_name_plural = Inflector::humanize(Inflector::pluralize($model_name)); 35 $this->model_name_human = Inflector::humanize($model_name); 35 $this->model_name_human = Inflector::humanize($model_name); 36 36 if(!class_exists($this->model_class, true)) { 37 37 $this->raise("Trying to use scaffolding on a non-existing Model ".$model_name, "Unknown Model", "404"); 38 } 39 $this->controller_name = $controller_name; 38 } 39 $this->controller_name = $controller_name; 40 40 } 41 41 42 42 function index() { 43 $model_class = $this->model_class; 44 $model = new $model_class(); 45 $this-> table_info = $model->table_info;43 $model_class = $this->model_class; 44 $model = new $model_class(); 45 $this->content_columns = $model->content_columns; 46 46 $this->models = $model->find_all(); 47 47 } 48 49 function show() { 50 $model_class = $this->model_class; 48 49 function show() { 50 $model_class = $this->model_class; 51 51 $model = new $model_class(); 52 $this->model = $model->find($_REQUEST['id']); 52 $this->model = $model->find($_REQUEST['id']); 53 53 } 54 54 55 55 function add() { 56 $model_class = $this->model_class; 56 $model_class = $this->model_class; 57 57 $this->model = new $model_class($_REQUEST['model']); 58 58 if($_POST) { … … 63 63 } else { 64 64 $_SESSION['flash']['error'] = "Error adding ".$this->model_name_human." to the database."; 65 } 65 } 66 66 } 67 67 } 68 68 69 69 function edit() { 70 $model_class = $this->model_class; 70 $model_class = $this->model_class; 71 71 $model = new $model_class(); 72 $this->model = $model->find($_REQUEST['id']); 72 $this->model = $model->find($_REQUEST['id']); 73 73 74 74 if($_POST) { 75 75 if($this->model->save($_REQUEST['model'])) { 76 $_SESSION['flash']['notice'] = $this->model_name_human." was successfully updated.";76 Session::flash('notice', $this->model_name_human." was successfully updated."); 77 77 $this->show(); 78 78 $this->render_action = "show"; 79 79 } else { 80 80 $_SESSION['flash']['error'] = "Error saving ".$this->model_name_human." to the database."; 81 } 81 } 82 82 } 83 83 } … … 85 85 function delete() { 86 86 if($_REQUEST['id'] > 0) { 87 $model_class = $this->model_class; 87 $model_class = $this->model_class; 88 88 $model = new $model_class(); 89 $model = $model->find($_REQUEST['id']); 89 $model = $model->find($_REQUEST['id']); 90 90 if($model->delete()) { 91 91 $_SESSION['flash']['notice'] = $this->model_name_human." was successfully deleted."; 92 92 } else { 93 93 $_SESSION['flash']['error'] = "Error deleting ".$this->model_name_human." from the database."; 94 } 94 } 95 95 } 96 $this->index(); 97 $this->render_action = "index"; 98 } 99 100 } 96 $this->index(); 97 $this->render_action = "index"; 98 } 101 99 102 function link_to($url_text, $controller_name, $params = null) {103 $url = "<a href=\"/";104 if(!is_null($params)) {105 if($params[':controller']) {106 $url .= $params[':controller']."/";107 } elseif($controller_name) {108 $url .= $controller_name."/";109 }110 if($params[':action']) {111 $url .= $params[':action']."/";112 }113 if($params[':id']) {114 $url .= $params[':id']->id;115 }116 }117 $url .= "\">$url_text</a>";118 return $url;119 100 } 120 101
