Show
Ignore:
Timestamp:
01/02/06 22:19:42 (6 years ago)
Author:
john
Message:

more bug fixes for scaffolding and added input filtering

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/scaffold_controller.php

    r106 r107  
    2525class ScaffoldController extends ActionController { 
    2626 
    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); 
    3229        $this->model_name = Inflector::camelize($model_name); 
     30        $this->model_object_name = Inflector::singularize($model_name); 
    3331        $this->model_class = Inflector::classify($model_name); 
    3432        $this->model_name_plural = Inflector::humanize(Inflector::pluralize($model_name)); 
     
    3735            $this->raise("Trying to use scaffolding on a non-existing Model ".$model_name, "Unknown Model", "404"); 
    3836        } 
    39         $this->controller_name = $controller_name; 
    4037    } 
    4138 
     
    5047        $model_class = $this->model_class; 
    5148        $model = new $model_class(); 
    52         $this->model = $model->find($_REQUEST['id']); 
     49        $this->{$this->model_object_name} = $model->find($_REQUEST['id']); 
    5350    } 
    5451 
    5552    function add() { 
    5653        $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]); 
    5855        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")); 
    6359            } 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."); 
    6561            } 
    6662        } 
     
    7066        $model_class = $this->model_class; 
    7167        $model = new $model_class(); 
    72         $this->model = $model->find($_REQUEST['id']); 
    73      
     68        $this->{$this->model_object_name} = $model->find($_REQUEST['id']);   
    7469        if($_POST) { 
    75             if($this->model->save($_REQUEST['model'])) { 
     70            if($this->{$this->model_object_name}->save($_POST[$this->model_object_name])) { 
    7671                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})); 
    7973            } 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."); 
    8175            } 
    8276        } 
     
    8983            $model = $model->find($_REQUEST['id']); 
    9084            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."); 
    9286            } 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."); 
    9488            } 
    9589        } 
    96         $this->index(); 
    97         $this->render_action = "index"; 
     90        $this->redirect_to = url_for(array(":action" => "index")); 
    9891    } 
    9992