Show
Ignore:
Timestamp:
01/01/06 21:37:32 (6 years ago)
Author:
john
Message:

added a bunch of stuff for scaffolding

Files:
1 modified

Legend:

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

    r72 r106  
    2525class ScaffoldController extends ActionController { 
    2626 
    27     function __construct($model_name, $controller_name, $action = "index") {       
     27    function __construct($model_name, $controller_name, $action = "index") { 
    2828        if($action == "") { 
    2929            $action = "index"; 
     
    3333        $this->model_class = Inflector::classify($model_name); 
    3434        $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); 
    3636        if(!class_exists($this->model_class, true)) { 
    3737            $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; 
    4040    } 
    41      
     41 
    4242    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; 
    4646        $this->models = $model->find_all(); 
    4747    } 
    48     
    49     function show() {          
    50         $model_class = $this->model_class;      
     48 
     49    function show() { 
     50        $model_class = $this->model_class; 
    5151        $model = new $model_class(); 
    52         $this->model = $model->find($_REQUEST['id']);        
     52        $this->model = $model->find($_REQUEST['id']); 
    5353    } 
    5454 
    5555    function add() { 
    56         $model_class = $this->model_class;      
     56        $model_class = $this->model_class; 
    5757        $this->model = new $model_class($_REQUEST['model']); 
    5858        if($_POST) { 
     
    6363            } else { 
    6464                $_SESSION['flash']['error'] = "Error adding ".$this->model_name_human." to the database."; 
    65             }            
     65            } 
    6666        } 
    6767    } 
    6868     
    6969    function edit() { 
    70         $model_class = $this->model_class;      
     70        $model_class = $this->model_class; 
    7171        $model = new $model_class(); 
    72         $this->model = $model->find($_REQUEST['id']);        
     72        $this->model = $model->find($_REQUEST['id']); 
    7373     
    7474        if($_POST) { 
    7575            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."); 
    7777                $this->show(); 
    7878                $this->render_action = "show"; 
    7979            } else { 
    8080                $_SESSION['flash']['error'] = "Error saving ".$this->model_name_human." to the database."; 
    81             }            
     81            } 
    8282        } 
    8383    } 
     
    8585    function delete() { 
    8686        if($_REQUEST['id'] > 0) { 
    87             $model_class = $this->model_class;      
     87            $model_class = $this->model_class; 
    8888            $model = new $model_class(); 
    89             $model = $model->find($_REQUEST['id']);  
     89            $model = $model->find($_REQUEST['id']); 
    9090            if($model->delete()) { 
    9191                $_SESSION['flash']['notice'] = $this->model_name_human." was successfully deleted."; 
    9292            } else { 
    9393                $_SESSION['flash']['error'] = "Error deleting ".$this->model_name_human." from the database."; 
    94             }            
     94            } 
    9595        } 
    96         $this->index(); 
    97         $this->render_action = "index"; 
    98     }        
    99      
    100 } 
     96        $this->index(); 
     97        $this->render_action = "index"; 
     98    } 
    10199 
    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; 
    119100} 
    120101