当前位置: 首页>>代码示例>>PHP>>正文


PHP CakeSchema::__values方法代码示例

本文整理汇总了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);
//.........这里部分代码省略.........
开发者ID:subh,项目名称:raleigh-workshop-08,代码行数:101,代码来源:model.php

示例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;
//.........这里部分代码省略.........
开发者ID:uuking,项目名称:wildflower,代码行数:101,代码来源:model.php


注:本文中的CakeSchema::__values方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。