PHPonTrax
[ class tree: PHPonTrax ] [ index: PHPonTrax ] [ all elements ]

Source for file scaffold_controller.php

Documentation is available at scaffold_controller.php

  1. <?php
  2. /**
  3.  *  File containing the ScaffoldController class
  4.  *
  5.  *  (PHP 5)
  6.  *
  7.  *  @package PHPonTrax
  8.  *  @version $Id: scaffold_controller.php 201 2006-05-25 08:58:10Z john $
  9.  *  @copyright (c) 2005 John Peterson
  10.  *
  11.  *   Permission is hereby granted, free of charge, to any person obtaining
  12.  *   a copy of this software and associated documentation files (the
  13.  *   "Software"), to deal in the Software without restriction, including
  14.  *   without limitation the rights to use, copy, modify, merge, publish,
  15.  *   distribute, sublicense, and/or sell copies of the Software, and to
  16.  *   permit persons to whom the Software is furnished to do so, subject to
  17.  *   the following conditions:
  18.  *
  19.  *   The above copyright notice and this permission notice shall be
  20.  *   included in all copies or substantial portions of the Software.
  21.  *
  22.  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23.  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24.  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25.  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26.  *   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27.  *   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28.  *   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29.  */
  30.  
  31. /**
  32.  *
  33.  *  @todo Document this class
  34.  */
  35.  
  36.     /**
  37.      *
  38.      *  @todo Document this method
  39.      */
  40.     function __construct($model_name{
  41.         $model_name strtolower($model_name);
  42.         $this->model_name Inflector::camelize($model_name);
  43.         $this->model_object_name Inflector::singularize($model_name);
  44.         $this->model_class Inflector::classify($model_name);
  45.         $this->model_name_plural Inflector::pluralize($model_name);
  46.         $this->model_name_human Inflector::humanize($model_name);
  47.         if(!class_exists($this->model_classtrue)) {
  48.             $this->raise("Trying to use scaffolding on a non-existing Model ".$model_name"Unknown Model""404");
  49.         }
  50.     }
  51.  
  52.     /**
  53.      *
  54.      *  @todo Document this method
  55.      */
  56.     function index({
  57.         $model_class $this->model_class;
  58.         $model new $model_class();
  59.         $this->content_columns $model->content_columns;
  60.         $this->models $model->find_all();
  61.     }
  62.  
  63.     /**
  64.      *
  65.      *  @todo Document this method
  66.      */
  67.     function show({
  68.         $model_class $this->model_class;
  69.         $model new $model_class();
  70.         $this->{$this->model_object_name$model->find($_REQUEST['id']);
  71.     }
  72.  
  73.     /**
  74.      *
  75.      *  @todo Document this method
  76.      */
  77.     function add({
  78.         $model_class $this->model_class;
  79.         $this->{$this->model_object_namenew $model_class($_REQUEST[$this->model_object_name]);
  80.         if($_POST{
  81.             if($this->{$this->model_object_name}->save($_POST[$this->model_object_name])) {
  82.                   Session::flash('notice'$this->model_name_human." was successfully created.");
  83.                 $this->redirect_to url_for(array(":action" => "index"));
  84.             else {
  85.                   Session::flash('error'"Error adding ".$this->model_name_human." to the database.");
  86.             }
  87.         }
  88.     }
  89.     
  90.     /**
  91.      *
  92.      *  @todo Document this method
  93.      */
  94.     function edit({
  95.         $model_class $this->model_class;
  96.         $model new $model_class();
  97.         $this->{$this->model_object_name$model->find($_REQUEST['id']);    
  98.         if($_POST{
  99.             if($this->{$this->model_object_name}->save($_POST[$this->model_object_name])) {
  100.                   Session::flash('notice'$this->model_name_human." was successfully updated.");
  101.                 $this->redirect_to url_for(array(":action" => "show"":id" => $this->{$this->model_object_name}));
  102.             else {
  103.                   Session::flash('error'"Error saving ".$this->model_name_human." to the database.");
  104.             }
  105.         }
  106.     }
  107.     
  108.     /**
  109.      *
  110.      *  @todo Document this method
  111.      */
  112.     function delete({
  113.         if($_REQUEST['id'0{
  114.             $model_class $this->model_class;
  115.             $model new $model_class();
  116.             $model $model->find($_REQUEST['id']);
  117.             if($model->delete()) {
  118.                   Session::flash('notice'$this->model_name_human." was successfully deleted.");
  119.               else {
  120.                   Session::flash('error'"Error deleting ".$this->model_name_human." from the database.");
  121.             }
  122.         }
  123.         $this->redirect_to url_for(array(":action" => "index"));
  124.     }
  125.  
  126. }
  127.  
  128. // -- set Emacs parameters --
  129. // Local variables:
  130. // tab-width: 4
  131. // c-basic-offset: 4
  132. // c-hanging-comment-ender-p: nil
  133. // indent-tabs-mode: nil
  134. // End:
  135. ?>

Documentation generated on Mon, 21 May 2007 22:28:47 -0600 by phpDocumentor 1.3.2