本文整理匯總了PHP中CakeSchema::__values方法的典型用法代碼示例。如果您正苦於以下問題:PHP CakeSchema::__values方法的具體用法?PHP CakeSchema::__values怎麽用?PHP CakeSchema::__values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CakeSchema
的用法示例。
在下文中一共展示了CakeSchema::__values方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fixture
/**
* Builds the tests fixtures for the model and create the file
*
* @param string $model the name of the model
* @param string $useTable table name
* @return array $records, used in ModelTask::bakeTest() to create $expected
* @todo move this to a task
*/
function fixture($model, $useTable = null)
{
if (!class_exists('CakeSchema')) {
App::import('Model', 'Schema');
}
$out = "\nclass {$model}Fixture extends CakeTestFixture {\n";
$out .= "\tvar \$name = '{$model}';\n";
if (!$useTable) {
$useTable = Inflector::tableize($model);
} else {
$out .= "\tvar \$table = '{$useTable}';\n";
}
$schema = new CakeSchema();
$data = $schema->read(array('models' => false));
if (!isset($data['tables'][$useTable])) {
return false;
}
$tables[$model] = $data['tables'][$useTable];
foreach ($tables as $table => $fields) {
if (!is_numeric($table) && $table !== 'missing') {
$out .= "\tvar \$fields = array(\n";
$records = array();
if (is_array($fields)) {
$cols = array();
foreach ($fields as $field => $value) {
if ($field != 'indexes') {
if (is_string($value)) {
$type = $value;
$value = array('type' => $type);
}
$col = "\t\t\t'{$field}' => array('type'=>'" . $value['type'] . "', ";
switch ($value['type']) {
case 'integer':
$insert = 1;
break;
case 'string':
$insert = "Lorem ipsum dolor sit amet";
if (!empty($value['length'])) {
$insert = substr($insert, 0, (int) $value['length'] - 2);
}
$insert = "'{$insert}'";
break;
case 'datetime':
$ts = date('Y-m-d H:i:s');
$insert = "'{$ts}'";
break;
case 'date':
$ts = date('Y-m-d');
$insert = "'{$ts}'";
break;
case 'time':
$ts = date('H:i:s');
$insert = "'{$ts}'";
break;
case 'boolean':
$insert = 1;
break;
case 'text':
$insert = '\'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida,
phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam,
vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit,
feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.
Orci aliquet, in lorem et velit maecenas luctus, wisi nulla at, mauris nam ut a, lorem et et elit eu.
Sed dui facilisi, adipiscing mollis lacus congue integer, faucibus consectetuer eros amet sit sit,
magna dolor posuere. Placeat et, ac occaecat rutrum ante ut fusce. Sit velit sit porttitor non enim purus,
id semper consectetuer justo enim, nulla etiam quis justo condimentum vel, malesuada ligula arcu. Nisl neque,
ligula cras suscipit nunc eget, et tellus in varius urna odio est. Fuga urna dis metus euismod laoreet orci,
litora luctus suspendisse sed id luctus ut. Pede volutpat quam vitae, ut ornare wisi. Velit dis tincidunt,
pede vel eleifend nec curabitur dui pellentesque, volutpat taciti aliquet vivamus viverra, eget tellus ut
feugiat lacinia mauris sed, lacinia et felis.\'';
break;
}
$records[] = "\t\t\t'{$field}' => {$insert}";
unset($value['type']);
$col .= join(', ', $schema->__values($value));
} else {
$col = "\t\t\t'indexes' => array(";
$props = array();
foreach ((array) $value as $key => $index) {
$props[] = "'{$key}' => array(" . join(', ', $schema->__values($index)) . ")";
}
$col .= join(', ', $props);
}
$col .= ")";
$cols[] = $col;
}
$out .= join(",\n", $cols);
}
$out .= "\n\t\t\t);\n";
}
}
$records = join(",\n", $records);
//.........這裏部分代碼省略.........
示例2: fixture
/**
* Builds the tests fixtures for the model and create the file
*
* @param string $model the name of the model
* @param string $useTable table name
* @return array $records, used in ModelTask::bakeTest() to create $expected
* @todo move this to a task
*/
function fixture($model, $useTable = null)
{
if (!class_exists('CakeSchema')) {
App::import('Model', 'Schema');
}
$out = "\nclass {$model}Fixture extends CakeTestFixture {\n";
$out .= "\tvar \$name = '{$model}';\n";
if (!$useTable) {
$useTable = Inflector::tableize($model);
} else {
$out .= "\tvar \$table = '{$useTable}';\n";
}
$schema = new CakeSchema();
$data = $schema->read(array('models' => false, 'connection' => $this->useDbConfig));
if (!isset($data['tables'][$useTable])) {
return false;
}
$tables[$model] = $data['tables'][$useTable];
foreach ($tables as $table => $fields) {
if (!is_numeric($table) && $table !== 'missing') {
$out .= "\tvar \$fields = array(\n";
$records = array();
if (is_array($fields)) {
$cols = array();
foreach ($fields as $field => $value) {
if ($field != 'indexes') {
if (is_string($value)) {
$type = $value;
$value = array('type' => $type);
}
$col = "\t\t'{$field}' => array('type'=>'" . $value['type'] . "', ";
switch ($value['type']) {
case 'float':
case 'integer':
$insert = 1;
break;
case 'binary':
case 'string':
$insert = "Lorem ipsum dolor sit amet";
if (!empty($value['length'])) {
$insert = substr($insert, 0, (int) $value['length'] - 2);
}
$insert = "'{$insert}'";
break;
case 'datetime':
$ts = date('Y-m-d H:i:s');
$insert = "'{$ts}'";
break;
case 'date':
$ts = date('Y-m-d');
$insert = "'{$ts}'";
break;
case 'time':
$ts = date('H:i:s');
$insert = "'{$ts}'";
break;
case 'boolean':
$insert = 1;
break;
case 'text':
$insert = "'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida,";
$insert .= "phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam,";
$insert .= "vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit,";
$insert .= "feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.'";
break;
}
$records[] = "\t\t'{$field}' => {$insert}";
unset($value['type']);
$col .= implode(', ', $schema->__values($value));
} else {
$col = "\t\t'indexes' => array(";
$props = array();
foreach ((array) $value as $key => $index) {
$props[] = "'{$key}' => array(" . implode(', ', $schema->__values($index)) . ")";
}
$col .= implode(', ', $props);
}
$col .= ")";
$cols[] = $col;
}
$out .= implode(",\n", $cols);
}
$out .= "\n\t);\n";
}
}
$records = implode(",\n", $records);
$out .= "\tvar \$records = array(array(\n{$records}\n\t));\n";
$out .= "}\n";
$path = TESTS . DS . 'fixtures' . DS;
if (isset($this->plugin)) {
$pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS;
$path = APP . $pluginPath . 'tests' . DS . 'fixtures' . DS;
//.........這裏部分代碼省略.........