⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bake.php.svn-base

📁 j2me is based on j2mepolish, client & server for mobile application. server part
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
			}		}		$database = '';		while ($database == '') {			$database = $this->getInput('What is the name of the database you will be using?', null, 'cake');			if ($database == '')  {				$this->stdout('The database name you supplied was empty. Please try again.');			}		}		$prefix = '';		while ($prefix == '') {			$prefix = $this->getInput('Enter a table prefix?', null, 'n');		}		if(low($prefix) == 'n') {			$prefix = '';		}		$this->stdout('');		$this->hr();		$this->stdout('The following database configuration will be created:');		$this->hr();		$this->stdout("Driver:        $driver");		$this->stdout("Connection:    $connect");		$this->stdout("Host:          $host");		$this->stdout("User:          $login");		$this->stdout("Pass:          " . str_repeat('*', strlen($password)));		$this->stdout("Database:      $database");		$this->stdout("Table prefix:  $prefix");		$this->hr();		$looksGood = $this->getInput('Look okay?', array('y', 'n'), 'y');		if (low($looksGood) == 'y' || low($looksGood) == 'yes') {			$this->bakeDbConfig($driver, $connect, $host, $login, $password, $database, $prefix);		} else {			$this->stdout('Bake Aborted.');		}	}/** * Action to create a Model. * */	function doModel()	{		$this->hr();		$this->stdout('Model Bake:');		$this->hr();		$this->interactive = true;		$useTable = null;		$primaryKey = 'id';		$validate = array();		$associations = array();		/*$usingDefault = $this->getInput('Will your model be using a database connection setting other than the default?');		if (low($usingDefault) == 'y' || low($usingDefault) == 'yes')		{			$useDbConfig = $this->getInput('Please provide the name of the connection you wish to use.');		}*/		$useDbConfig = 'default';		$this->__doList($useDbConfig);		$enteredModel = '';		while ($enteredModel == '') {			$enteredModel = $this->getInput('Enter a number from the list above, or type in the name of another model.');			if ($enteredModel == '' || intval($enteredModel) > count($this->__modelNames)) {				$this->stdout('Error:');				$this->stdout("The model name you supplied was empty, or the number \nyou selected was not an option. Please try again.");				$enteredModel = '';			}		}		if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->__modelNames)) {			$currentModelName = $this->__modelNames[intval($enteredModel) - 1];		} else {			$currentModelName = $enteredModel;		}		$useTable = Inflector::tableize($currentModelName);		if(array_search($useTable, $this->__tables) === false) {			$this->stdout("\nGiven your model named '$currentModelName', Cake would expect a database table named '" . $useTable . "'.");			$tableIsGood = $this->getInput('Is this correct?', array('y','n'), 'y');		}		if (low($tableIsGood) == 'n' || low($tableIsGood) == 'no') {			$useTable = $this->getInput('What is the name of the table (enter "null" to use NO table)?');		}		$wannaDoValidation = $this->getInput('Would you like to supply validation criteria for the fields in your model?', array('y','n'), 'y');		$tempModel = new Model(false, $useTable);		$db =& ConnectionManager::getDataSource($useDbConfig);		$modelFields = $db->describe($tempModel);		if(!isset($modelFields[0]['name']) && $modelFields[0]['name'] != 'id') {			$primaryKey = $this->getInput('What is the primaryKey', null, 'id');		}		$validate = array();		if (array_search($useTable, $this->__tables) !== false && (low($wannaDoValidation) == 'y' || low($wannaDoValidation) == 'yes')) {			foreach($modelFields as $field) {				$this->stdout('');				$prompt .= 'Name: ' . $field['name'] . "\n";				$prompt .= 'Type: ' . $field['type'] . "\n";				$prompt .= '---------------------------------------------------------------'."\n";				$prompt .= 'Please select one of the following validation options:'."\n";				$prompt .= '---------------------------------------------------------------'."\n";				$prompt .= "1- VALID_NOT_EMPTY\n";				$prompt .= "2- VALID_EMAIL\n";				$prompt .= "3- VALID_NUMBER\n";				$prompt .= "4- VALID_YEAR\n";				$prompt .= "5- Do not do any validation on this field.\n\n";				$prompt .= "... or enter in a valid regex validation string.\n\n";				if($field['name'] == 'id' || $field['name'] == 'created' || $field['name'] == 'modified') {					$validation = $this->getInput($prompt, null, '5');				} else {					$validation = $this->getInput($prompt, null, '1');				}				switch ($validation) {					case '1':						$validate[$field['name']] = 'VALID_NOT_EMPTY';						break;					case '2':						$validate[$field['name']] = 'VALID_EMAIL';						break;					case '3':						$validate[$field['name']] = 'VALID_NUMBER';						break;					case '4':						$validate[$field['name']] = 'VALID_YEAR';						break;					case '5':						break;					default:						$validate[$field['name']] = $validation;					break;				}			}		}		$wannaDoAssoc = $this->getInput('Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)?', array('y','n'), 'y');		if((low($wannaDoAssoc) == 'y' || low($wannaDoAssoc) == 'yes')) {			$this->stdout('One moment while I try to detect any associations...');			$possibleKeys = array();			//Look for belongsTo			$i = 0;			foreach($modelFields as $field) {				$offset = strpos($field['name'], '_id');				if($offset !== false) {					$tmpModelName = $this->__modelNameFromKey($field['name']);					$associations['belongsTo'][$i]['alias'] = $tmpModelName;					$associations['belongsTo'][$i]['className'] = $tmpModelName;					$associations['belongsTo'][$i]['foreignKey'] = $field['name'];					$i++;				}			}			//Look for hasOne and hasMany and hasAndBelongsToMany			$i = 0;			$j = 0;			foreach($this->__tables as $otherTable) {				$tempOtherModel = & new Model(false, $otherTable);				$modelFieldsTemp = $db->describe($tempOtherModel);				foreach($modelFieldsTemp as $field) {					if($field['type'] == 'integer' || $field['type'] == 'string') {						$possibleKeys[$otherTable][] = $field['name'];					}					if($field['name'] == $this->__modelKey($currentModelName)) {						$tmpModelName = $this->__modelName($otherTable);						$associations['hasOne'][$j]['alias'] = $tmpModelName;						$associations['hasOne'][$j]['className'] = $tmpModelName;						$associations['hasOne'][$j]['foreignKey'] = $field['name'];						$associations['hasMany'][$j]['alias'] = $tmpModelName;						$associations['hasMany'][$j]['className'] = $tmpModelName;						$associations['hasMany'][$j]['foreignKey'] = $field['name'];						$j++;					}				}				$offset = strpos($otherTable, $useTable . '_');				if($offset !== false) {					$offset = strlen($useTable . '_');					$tmpModelName = $this->__modelName(substr($otherTable, $offset));					$associations['hasAndBelongsToMany'][$i]['alias'] = $tmpModelName;					$associations['hasAndBelongsToMany'][$i]['className'] = $tmpModelName;					$associations['hasAndBelongsToMany'][$i]['foreignKey'] = $this->__modelKey($currentModelName);					$associations['hasAndBelongsToMany'][$i]['associationForeignKey'] = $this->__modelKey($tmpModelName);					$associations['hasAndBelongsToMany'][$i]['joinTable'] = $otherTable;					$i++;				}				$offset = strpos($otherTable, '_' . $useTable);				if ($offset !== false) {					$tmpModelName = $this->__modelName(substr($otherTable, 0, $offset));					$associations['hasAndBelongsToMany'][$i]['alias'] = $tmpModelName;					$associations['hasAndBelongsToMany'][$i]['className'] = $tmpModelName;					$associations['hasAndBelongsToMany'][$i]['foreignKey'] = $this->__modelKey($currentModelName);					$associations['hasAndBelongsToMany'][$i]['associationForeignKey'] = $this->__modelKey($tmpModelName);					$associations['hasAndBelongsToMany'][$i]['joinTable'] = $otherTable;					$i++;				}			}			$this->stdout('Done.');			$this->hr();			//if none found...			if(empty($associations)) {				$this->stdout('None found.');			} else {				$this->stdout('Please confirm the following associations:');				$this->hr();				if(!empty($associations['belongsTo'])) {					$count = count($associations['belongsTo']);					for($i = 0; $i < $count; $i++) {						if($currentModelName == $associations['belongsTo'][$i]['alias']) {							$response = $this->getInput("{$currentModelName} belongsTo {$associations['belongsTo'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y');							if('y' == low($response) || 'yes' == low($response)) {								$associations['belongsTo'][$i]['alias'] = $this->getInput("So what is the alias?", null, $associations['belongsTo'][$i]['alias']);							}							if($currentModelName != $associations['belongsTo'][$i]['alias']) {								$response = $this->getInput("$currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}?", array('y','n'), 'y');							} else {								$response = 'n';							}						} else {							$response = $this->getInput("$currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}?", array('y','n'), 'y');						}						if('n' == low($response) || 'no' == low($response)) {							unset($associations['belongsTo'][$i]);						}					}					$associations['belongsTo'] = array_merge($associations['belongsTo']);				}				if(!empty($associations['hasOne'])) {					$count = count($associations['hasOne']);					for($i = 0; $i < $count; $i++) {						if($currentModelName == $associations['hasOne'][$i]['alias']) {							$response = $this->getInput("{$currentModelName} hasOne {$associations['hasOne'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y');							if('y' == low($response) || 'yes' == low($response)) {								$associations['hasOne'][$i]['alias'] = $this->getInput("So what is the alias?", null, $associations['hasOne'][$i]['alias']);							}							if($currentModelName != $associations['hasOne'][$i]['alias']) {								$response = $this->getInput("$currentModelName hasOne {$associations['hasOne'][$i]['alias']}?", array('y','n'), 'y');							} else {								$response = 'n';							}						} else {							$response = $this->getInput("$currentModelName hasOne {$associations['hasOne'][$i]['alias']}?", array('y','n'), 'y');						}						if('n' == low($response) || 'no' == low($response)) {							unset($associations['hasOne'][$i]);						}					}					$associations['hasOne'] = array_merge($associations['hasOne']);				}				if(!empty($associations['hasMany'])) {					$count = count($associations['hasMany']);					for($i = 0; $i < $count; $i++) {						if($currentModelName == $associations['hasMany'][$i]['alias']) {							$response = $this->getInput("{$currentModelName} hasMany {$associations['hasMany'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y');							if('y' == low($response) || 'yes' == low($response)) {								$associations['hasMany'][$i]['alias'] = $this->getInput("So what is the alias?", null, $associations['hasMany'][$i]['alias']);							}							if($currentModelName != $associations['hasMany'][$i]['alias']) {								$response = $this->getInput("$currentModelName hasMany {$associations['hasMany'][$i]['alias']}?", array('y','n'), 'y');							} else {								$response = 'n';							}						} else {							$response = $this->getInput("$currentModelName hasMany {$associations['hasMany'][$i]['alias']}?", array('y','n'), 'y');						}						if('n' == low($response) || 'no' == low($response)) {							unset($associations['hasMany'][$i]);						}					}					$associations['hasMany'] = array_merge($associations['hasMany']);				}				if(!empty($associations['hasAndBelongsToMany'])) {					$count = count($associations['hasAndBelongsToMany']);					for($i = 0; $i < $count; $i++) {						if($currentModelName == $associations['hasAndBelongsToMany'][$i]['alias']) {							$response = $this->getInput("{$currentModelName} hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}\nThis looks like a self join. Do you want to specify an alternate association alias?", array('y','n'), 'y');							if('y' == low($response) || 'yes' == low($response)) {								$associations['hasAndBelongsToMany'][$i]['alias'] = $this->getInput("So what is the alias?", null, $associations['hasAndBelongsToMany'][$i]['alias']);							}							if($currentModelName != $associations['hasAndBelongsToMany'][$i]['alias']) {								$response = $this->getInput("$currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}?", array('y','n'), 'y');							} else {								$response = 'n';							}						} else {							$response = $this->getInput("$currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}?", array('y','n'), 'y');						}						if('n' == low($response) || 'no' == low($response)) {							unset($associations['hasAndBelongsToMany'][$i]);						}					}					$associations['hasAndBelongsToMany'] = array_merge($associations['hasAndBelongsToMany']);				}			}			$wannaDoMoreAssoc = $this->getInput('Would you like to define some additional model associations?', array('y','n'), 'y');			while((low($wannaDoMoreAssoc) == 'y' || low($wannaDoMoreAssoc) == 'yes')) {				$assocs = array(1=>'belongsTo', 2=>'hasOne', 3=>'hasMany', 4=>'hasAndBelongsToMany');				$bad = true;				while($bad) {					$this->stdout('What is the association type?');					$prompt = "1- belongsTo\n";					$prompt .= "2- hasOne\n";					$prompt .= "3- hasMany\n";					$prompt .= "4- hasAndBelongsToMany\n";					$assocType = intval($this->getInput($prompt, null, null));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -