scaffold.php.svn-base
来自「j2me is based on j2mepolish, client & se」· SVN-BASE 代码 · 共 432 行 · 第 1/2 页
SVN-BASE
432 行
<?php/* SVN FILE: $Id: scaffold.php 4015 2006-11-28 23:37:51Z phpnut $ *//** * Scaffold. * * Automatic forms and actions generation for rapid web application development. * * PHP versions 4 and 5 * * CakePHP : Rapid Development Framework <http://www.cakephp.org/> * Copyright (c) 2006, Cake Software Foundation, Inc. * 1785 E. Sahara Avenue, Suite 490-204 * Las Vegas, Nevada 89104 * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project * @package cake * @subpackage cake.cake.libs.controller * @since Cake v 0.10.0.1076 * @version $Revision: 4015 $ * @modifiedby $LastChangedBy: phpnut $ * @lastmodified $Date: 2006-11-28 17:37:51 -0600 (Tue, 28 Nov 2006) $ * @license http://www.opensource.org/licenses/mit-license.php The MIT License *//** * Scaffolding is a set of automatic views, forms and controllers for starting web development work faster. * * Scaffold inspects your database tables, and making educated guesses, sets up a * number of pages for each of your Models. These pages have data forms that work, * and afford the web developer an early look at the data, and the possibility to over-ride * scaffolded actions with custom-made ones. * * @package cake * @subpackage cake.cake.libs.controller */class Scaffold extends Object{/** * Name of view to render * * @var string */ var $actionView = null;/** * Class name of model * * @var unknown_type */ var $modelKey = null;/** * Controller object * * @var Controller */ var $controllerClass = null;/** * Name of scaffolded Model * * @var string */ var $modelName = null;/** * Title HTML element for current scaffolded view * * @var string */ var $scaffoldTitle = null;/** * Base URL * * @var string */ var $base = false;/** * Construct and set up given controller with given parameters. * * @param object $controller instance of controller * @param array $params */ function __construct(&$controller, $params) { $this->controllerClass =& $controller; $this->actionView = $controller->action; $this->modelKey = ucwords(Inflector::singularize($controller->name)); $this->scaffoldTitle = Inflector::humanize($this->modelKey); $this->viewPath = Inflector::underscore($controller->name); $this->controllerClass->pageTitle = $this->scaffoldTitle; $this->controllerClass->pageTitle = 'Scaffold :: ' . Inflector::humanize($controller->action) . ' :: ' . Inflector::humanize(Inflector::pluralize($this->modelKey)); $this->__scaffold($params); }/** * Renders a view view of scaffolded Model. * * @param array $params * @return A rendered view of a row from Models database table * @access private */ function __scaffoldView($params) { if ($this->controllerClass->_beforeScaffold('view')) { if(isset($params['pass'][0])){ $this->controllerClass->{$this->modelKey}->id = $params['pass'][0]; } elseif (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) { $this->controllerClass->Session->setFlash('No id set for ' . Inflector::humanize($this->modelKey) . '::view().'); $this->controllerClass->redirect('/' . Inflector::underscore($this->controllerClass->viewPath)); } else { return $this->controllerClass->flash('No id set for ' . Inflector::humanize($this->modelKey) . '::view().', '/' . Inflector::underscore($this->controllerClass->viewPath)); } $this->controllerClass->params['data'] = $this->controllerClass->{$this->modelKey}->read(); $this->controllerClass->set('data', $this->controllerClass->params['data']); $this->controllerClass->set('fieldNames',$this->controllerClass->generateFieldNames( $this->controllerClass->params['data'], false)); if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml')) { return $this->controllerClass->render($this->actionView, '', APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml'); } elseif (file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml')) { return $this->controllerClass->render($this->actionView, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml'); } else { return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'view.thtml'); } } elseif ($this->controllerClass->_scaffoldError('view') === false) { return $this->__scaffoldError(); } }/** * Renders List view of scaffolded Model. * * @param array $params * @return A rendered view listing rows from Models database table * @access private */ function __scaffoldIndex($params) { if ($this->controllerClass->_beforeScaffold('index')) { $this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames(null, false)); $this->controllerClass->{$this->modelKey}->recursive = 0; $this->controllerClass->set('data', $this->controllerClass->{$this->modelKey}->findAll()); if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml')) { return $this->controllerClass->render($this->actionView, '', APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml'); } elseif (file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml')) { return $this->controllerClass->render($this->actionView, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml'); } else { return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'index.thtml'); } } elseif ($this->controllerClass->_scaffoldError('index') === false) { return $this->__scaffoldError(); } }/** * Renders an Add or Edit view for scaffolded Model. * * @param array $params * @param string $params add or edit * @return A rendered view with a form to edit or add a record in the Models database table * @access private */ function __scaffoldForm($params = array(), $type) { $thtml = 'edit'; $form = 'Edit'; if ($type === 'add') { $thtml = 'add'; $form = 'Add'; } if ($this->controllerClass->_beforeScaffold($type)) { if ($type == 'edit') { if(isset($params['pass'][0])){ $this->controllerClass->{$this->modelKey}->id = $params['pass'][0]; } elseif (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) { $this->controllerClass->Session->setFlash('No id set for ' . Inflector::humanize($this->modelKey) . '::edit().'); $this->controllerClass->redirect('/' . Inflector::underscore($this->controllerClass->viewPath)); } else { return $this->controllerClass->flash('No id set for ' . Inflector::humanize($this->modelKey) . '::edit().', '/' . Inflector::underscore($this->controllerClass->viewPath)); } $this->controllerClass->params['data']=$this->controllerClass->{$this->modelKey}->read(); $this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames( $this->controllerClass->params['data'])); $this->controllerClass->set('data', $this->controllerClass->params['data']); } else { $this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames()); } $this->controllerClass->set('type', $form); if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $thtml . '.thtml')) { return $this->controllerClass->render($this->actionView, '', APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $thtml . '.thtml'); } elseif (file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml')) { return $this->controllerClass->render($this->actionView, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml'); } else { return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'edit.thtml'); } } elseif ($this->controllerClass->_scaffoldError($type) === false) { return $this->__scaffoldError();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?