當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CakeSchema::write方法代碼示例

本文整理匯總了PHP中CakeSchema::write方法的典型用法代碼示例。如果您正苦於以下問題:PHP CakeSchema::write方法的具體用法?PHP CakeSchema::write怎麽用?PHP CakeSchema::write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CakeSchema的用法示例。


在下文中一共展示了CakeSchema::write方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: generate

 /**
  * Read database and Write schema object
  * accepts a connection as first arg or path to save as second arg
  *
  * @return void
  */
 public function generate()
 {
     $this->out(__d('cake_console', 'Generating Schema...'));
     $options = array();
     if ($this->params['force']) {
         $options['models'] = false;
     } elseif (!empty($this->params['models'])) {
         $options['models'] = String::tokenize($this->params['models']);
     }
     $snapshot = false;
     if (isset($this->args[0]) && $this->args[0] === 'snapshot') {
         $snapshot = true;
     }
     if (!$snapshot && file_exists($this->Schema->path . DS . $this->params['file'])) {
         $snapshot = true;
         $prompt = __d('cake_console', "Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?");
         $result = strtolower($this->in($prompt, array('o', 's', 'q'), 's'));
         if ($result === 'q') {
             return $this->_stop();
         }
         if ($result === 'o') {
             $snapshot = false;
         }
     }
     $cacheDisable = Configure::read('Cache.disable');
     Configure::write('Cache.disable', true);
     $content = $this->Schema->read($options);
     $content['file'] = $this->params['file'];
     Configure::write('Cache.disable', $cacheDisable);
     if ($snapshot === true) {
         $fileName = rtrim($this->params['file'], '.php');
         $Folder = new Folder($this->Schema->path);
         $result = $Folder->read();
         $numToUse = false;
         if (isset($this->params['snapshot'])) {
             $numToUse = $this->params['snapshot'];
         }
         $count = 0;
         if (!empty($result[1])) {
             foreach ($result[1] as $file) {
                 if (preg_match('/' . preg_quote($fileName) . '(?:[_\\d]*)?\\.php$/', $file)) {
                     $count++;
                 }
             }
         }
         if ($numToUse !== false) {
             if ($numToUse > $count) {
                 $count = $numToUse;
             }
         }
         $content['file'] = $fileName . '_' . $count . '.php';
     }
     if ($this->Schema->write($content)) {
         $this->out(__d('cake_console', 'Schema file: %s generated', $content['file']));
         $this->_stop();
     } else {
         $this->err(__d('cake_console', 'Schema file: %s generated'));
         $this->_stop();
     }
 }
開發者ID:sanyaade-machine-learning,項目名稱:Catool,代碼行數:66,代碼來源:SchemaShell.php

示例2: generate

 /**
  * Read database and Write schema object
  * accepts a connection as first arg or path to save as second arg
  *
  */
 public function generate()
 {
     $this->out(__('Generating Schema...'));
     $options = array();
     if (isset($this->params['force'])) {
         $options = array('models' => false);
     }
     $snapshot = false;
     if (isset($this->args[0]) && $this->args[0] === 'snapshot') {
         $snapshot = true;
     }
     if (!$snapshot && file_exists($this->Schema->path . DS . $this->params['file'])) {
         $snapshot = true;
         $result = strtolower($this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's'));
         if ($result === 'q') {
             return $this->_stop();
         }
         if ($result === 'o') {
             $snapshot = false;
         }
     }
     $content = $this->Schema->read($options);
     $content['file'] = $this->params['file'];
     if ($snapshot === true) {
         $Folder = new Folder($this->Schema->path);
         $result = $Folder->read();
         $numToUse = false;
         if (isset($this->params['snapshot'])) {
             $numToUse = $this->params['snapshot'];
         }
         $count = 0;
         if (!empty($result[1])) {
             foreach ($result[1] as $file) {
                 if (preg_match('/schema(?:[_\\d]*)?\\.php$/', $file)) {
                     $count++;
                 }
             }
         }
         if ($numToUse !== false) {
             if ($numToUse > $count) {
                 $count = $numToUse;
             }
         }
         $fileName = rtrim($this->params['file'], '.php');
         $content['file'] = $fileName . '_' . $count . '.php';
     }
     if ($this->Schema->write($content)) {
         $this->out(__('Schema file: %s generated', $content['file']));
         $this->_stop();
     } else {
         $this->err(__('Schema file: %s generated'));
         $this->_stop();
     }
 }
開發者ID:no2key,項目名稱:Web-Framework-Benchmark,代碼行數:59,代碼來源:schema.php

示例3: CakeSchema

 function admin_export($id = null)
 {
     $this->layout = null;
     $this->autoRender = false;
     if (!$id) {
         $this->Session->setFlash(__('Invalid Node Schema', true));
         $this->redirect(array('action' => 'index'));
     }
     $this->NodeSchema->recursive = -1;
     $this->set('node_schemas', $node_schemas = $this->NodeSchema->read(null, $id));
     App::Import('CakeSchema');
     $CakeSchema = new CakeSchema();
     //debug($CakeSchema->tables);
     //debug($CakeSchema->read(array('default', 'test')));
     // The above only works for tables that have models, our models are only instantiated when needed in memory
     $db =& ConnectionManager::getDataSource($node_schemas['NodeSchema']['datasource']);
     //$tables = array();
     $Model = new Model(null, $node_schemas['NodeSchema']['table_name'], $node_schemas['NodeSchema']['datasource']);
     $Model->name = $Model->alias = Inflector::classify($node_schemas['NodeSchema']['table_name']);
     $Object = ClassRegistry::init(array('class' => Inflector::pluralize($Model->name), 'ds' => $node_schemas['NodeSchema']['datasource']));
     // These cause issues for one reason or another
     unset($Object->tableToModel);
     unset($Object->__associationKeys);
     unset($Object->__associations);
     unset($Object->_findMethods);
     // The rest here just aren't needed, but don't cause any issues (not sure if it makes the export any faster, but makes the import php file smaller)
     unset($Object->Behaviors);
     unset($Object->useCache);
     unset($Object->cacheSources);
     unset($Object->alias);
     unset($Object->recursive);
     unset($Object->primaryKey);
     unset($Object->table);
     unset($Object->useTable);
     unset($Object->displayField);
     unset($Object->useDbConfig);
     // This may eventually get used, if I can figure how to set it so it writes to the file
     // This is weird and doesn't even seem right, but it renames the property and works
     $Object->{$node_schemas}['NodeSchema']['table_name'] = $Object->_schema;
     unset($Object->_schema);
     $CakeSchema->path = $this->nodeSchemaPath;
     $CakeSchema->file = $node_schemas['NodeSchema']['table_name'] . '.php';
     $CakeSchema->write($Object);
     if (file_exists($this->nodeSchemaPath . DS . $CakeSchema->file)) {
         $file = $this->nodeSchemaPath . DS . $CakeSchema->file;
         header("Content-Type: application/octet-stream");
         header("Accept-Ranges: bytes");
         header("Content-Length: " . filesize($file));
         header("Content-Disposition: attachment; filename=" . $CakeSchema->file);
         readfile($file);
     } else {
         $this->Session->setFlash(__('Could not export node schema, ensure the path: ' . $this->nodeSchemaPath . ' is writeable by the server.', true));
         $this->redirect(array('action' => 'index'));
     }
 }
開發者ID:hgassen,項目名稱:node_schema,代碼行數:55,代碼來源:node_schemas_controller.php


注:本文中的CakeSchema::write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。