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


PHP Datasource\ConnectionManager类代码示例

本文整理汇总了PHP中Cake\Datasource\ConnectionManager的典型用法代码示例。如果您正苦于以下问题:PHP ConnectionManager类的具体用法?PHP ConnectionManager怎么用?PHP ConnectionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConnectionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 /**
  * setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->connection = ConnectionManager::get('test');
     $this->user = TableRegistry::get('Users', ['table' => 'counter_cache_users', 'connection' => $this->connection]);
     $this->post = new PostTable(['alias' => 'Post', 'table' => 'counter_cache_posts', 'connection' => $this->connection]);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:12,代码来源:CounterCacheBehaviorTest.php

示例2: getPlugins

 /**
  * Get plugin list from database
  */
 public static function getPlugins()
 {
     $conn = ConnectionManager::get('default');
     $newQuery = $conn->newQuery();
     $plugins = $newQuery->select('*')->from('spider_plugins_plugins')->where(['status' => 1])->order(['weight ASC'])->execute()->fetchAll('assoc');
     return $plugins;
 }
开发者ID:mohammadsaleh,项目名称:spider,代码行数:10,代码来源:SpiderPlugin.php

示例3: main

 /**
  * main
  *
  */
 public function main()
 {
     $schemaPo = APP . 'Locale' . DS . 'schema.pot';
     $conn = ConnectionManager::get('default');
     $collection = $conn->schemaCollection();
     $translations = new Translations();
     $tables = $collection->listTables();
     foreach ($tables as $table) {
         $translations->insert($table, Inflector::humanize(Inflector::underscore($table)));
         $translations->insert($table, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))));
         $columns = $collection->describe($table)->columns();
         foreach ($columns as $column) {
             $c = $collection->describe($table)->column($column);
             $comment = $c['comment'];
             $t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore($column)));
             $translations[] = $t;
             $t->setTranslation($comment);
             $t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))) . ' ' . Inflector::humanize(Inflector::underscore($column)));
             $translations[] = $t;
             $t->setTranslation($comment);
         }
     }
     $poString = $translations->toPoString();
     $caked = preg_replace('/msgctxt "([^"]+)"/i', '#: \\1', $poString);
     $this->createFile($schemaPo, $caked);
 }
开发者ID:k1low,项目名称:po,代码行数:30,代码来源:SchemaTask.php

示例4: save

 public function save()
 {
     if ($this->request->is('post')) {
         $attemptId = $this->request->data['attemptId'];
         $token = $this->request->data['token'];
         $rawSamples = $this->request->data['samples'];
         $happiness = $this->request->data['happiness'];
         $this->infolog("Samples Save attempted. Attempt: " . $attemptId . "; Happiness: " . $happiness . "; Samples: " . serialize($rawSamples));
         if ($attemptId && $token && $rawSamples && $this->Samples->Attempts->checkUserAttempt($this->Auth->user('id'), $attemptId, $token)) {
             $attempt = $this->Samples->Attempts->get($attemptId);
             //Get attempt, for saving happiness and identifying whether report has been submitted
             $samples = [];
             foreach ($rawSamples as $siteId => $schools) {
                 foreach ($schools as $schoolId => $children) {
                     foreach ($children as $childId => $types) {
                         foreach ($types as $typeId => $value) {
                             if ($value) {
                                 $sample = ['attempt_id' => $attemptId, 'site_id' => $siteId, 'school_id' => $schoolId, 'child_id' => $childId, 'sample_stage_id' => $typeId, 'before_submit' => !$attempt->report];
                                 array_push($samples, $sample);
                             }
                         }
                     }
                 }
             }
             //Note: Always create new entry - should never already be saved entries
             $samplesData = $this->Samples->newEntities($samples);
             if (!is_null($happiness)) {
                 $attempt->happiness = $happiness;
                 $attempt->sampling = true;
             } else {
                 $attempt = null;
             }
             $connection = ConnectionManager::get('default');
             $connection->transactional(function () use($samplesData, $attempt, $attemptId) {
                 foreach ($samplesData as $sample) {
                     if (!$this->Samples->save($sample)) {
                         $this->set('status', 'failed');
                         $this->infolog("Samples Save failed Attempt: " . $attemptId);
                         return false;
                     }
                 }
                 if (!is_null($attempt) && !$this->Samples->Attempts->save($attempt)) {
                     $this->set('status', 'failed');
                     $this->infolog("Samples Save failed Attempt: " . $attemptId);
                     return false;
                 }
                 $this->set('status', 'success');
                 $this->infolog("Samples Save succeeded. Attempt: " . $attemptId);
             });
         } else {
             $this->set('status', 'denied');
             $this->infolog("Samples Save denied. Attempt: " . $attemptId);
         }
     } else {
         $this->set('status', 'notpost');
         $this->infolog("Samples Save not POST ");
     }
     $this->viewBuilder()->layout('ajax');
     $this->render('/Element/ajaxmessage');
 }
开发者ID:jonmase,项目名称:outbreak,代码行数:60,代码来源:SamplesController.php

示例5: get

 /**
  * Get/Create an instance from the registry.
  *
  * When getting an instance, if it does not already exist,
  * a new instance will be created using the provide alias, and options.
  *
  * @param string $alias The name of the alias to get.
  * @param array $options Configuration options for the type constructor.
  * @return \Cake\ElasticSearch\Type
  */
 public static function get($alias, array $options = [])
 {
     if (isset(static::$instances[$alias])) {
         if (!empty($options) && static::$options[$alias] !== $options) {
             throw new RuntimeException(sprintf('You cannot configure "%s", it already exists in the registry.', $alias));
         }
         return static::$instances[$alias];
     }
     static::$options[$alias] = $options;
     list(, $classAlias) = pluginSplit($alias);
     $options = $options + ['name' => Inflector::underscore($classAlias)];
     if (empty($options['className'])) {
         $options['className'] = Inflector::camelize($alias);
     }
     $className = App::className($options['className'], 'Model/Type', 'Type');
     if ($className) {
         $options['className'] = $className;
     } else {
         if (!isset($options['name']) && strpos($options['className'], '\\') === false) {
             list(, $name) = pluginSplit($options['className']);
             $options['name'] = Inflector::underscore($name);
         }
         $options['className'] = 'Cake\\ElasticSearch\\Type';
     }
     if (empty($options['connection'])) {
         $connectionName = $options['className']::defaultConnectionName();
         $options['connection'] = ConnectionManager::get($connectionName);
     }
     static::$instances[$alias] = new $options['className']($options);
     return static::$instances[$alias];
 }
开发者ID:jeffersongoncalves,项目名称:elastic-search,代码行数:41,代码来源:TypeRegistry.php

示例6: execute

 /**
  * Dumps the current schema to be used when baking a diff
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input the input object
  * @param \Symfony\Component\Console\Output\OutputInterface $output the output object
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->setInput($input);
     $this->bootstrap($input, $output);
     $this->output($output);
     $path = $this->getOperationsPath($input);
     $connectionName = $input->getOption('connection') ?: 'default';
     $connection = ConnectionManager::get($connectionName);
     $collection = $connection->schemaCollection();
     $options = ['require-table' => true, 'plugin' => $this->getPlugin($input)];
     $tables = $this->getTablesToBake($collection, $options);
     $dump = [];
     if (empty($tables)) {
         $this->output()->writeln('<info>No tables were found : the dump file was not created</info>');
         return;
     }
     foreach ($tables as $table) {
         $schema = $collection->describe($table);
         $dump[$table] = $schema;
     }
     $filePath = $path . DS . 'schema-dump-' . $connectionName . '.lock';
     $output->writeln(sprintf('<info>Writing dump file `%s`...</info>', $filePath));
     if (file_put_contents($filePath, serialize($dump))) {
         $output->writeln(sprintf('<info>Dump file `%s` was successfully written</info>', $filePath));
     } else {
         $output->writeln(sprintf('<error>An error occurred while writing dump file `%s`</error>', $filePath));
     }
 }
开发者ID:daniels85,项目名称:SGL,代码行数:35,代码来源:Dump.php

示例7: tearDownAfterClass

 /**
  * Purge ConnectionManager configs.
  *
  * @return void
  */
 public static function tearDownAfterClass()
 {
     foreach (self::$datasources as $ds => $configs) {
         \Cake\Datasource\ConnectionManager::drop($ds);
     }
     \Cake\Utility\Security::salt('');
 }
开发者ID:loadsys,项目名称:cakephp-basic-seed,代码行数:12,代码来源:BasicSeedShellTest.php

示例8: setUp

 /**
  * setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->connection = ConnectionManager::get('test');
     $this->table = new Table(['table' => 'articles', 'connection' => $this->connection]);
     $this->fixtureData = [['id' => 1, 'author_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y'], ['id' => 2, 'author_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y'], ['id' => 3, 'author_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y']];
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:12,代码来源:ResultSetTest.php

示例9: init

 public function init()
 {
     parent::init();
     // 1. Not all fixtures want to use the dev db.
     if (is_null($this->tableName)) {
         return;
     }
     // 2. We need to do this to ensure that the tables really do use the connection to the
     // dev db.
     TableRegistry::remove($this->tableName);
     $table = TableRegistry::get($this->tableName, ['connection' => ConnectionManager::get('dev')]);
     //if(!is_null($this->joinTableName)) {
     //TableRegistry::remove($this->joinTableName);
     //$n=TableRegistry::get($this->joinTableName, ['connection' => ConnectionManager::get('fixture')]);
     //}
     // 3. Now build the query to retrieve the source records
     $query = new Query(ConnectionManager::get('dev'), $table);
     $query->find('all');
     //if(!is_null($this->order)) $query->order($this->order);
     //if(!is_null($this->joinTableName)) $query->leftJoin($this->joinTableName,'semesters.id = sections.semester_id');
     //$c=$query->count();
     // 4. Copy the records
     /* @var \Cake\ORM\Entity $record */
     foreach ($query as $record) {
         $this->records[] = $record->toArray();
     }
     // 5. Do this again to ensure that the table uses the 'test' connection.
     TableRegistry::remove($this->tableName);
     TableRegistry::get($this->tableName, ['connection' => ConnectionManager::get('test')]);
     //if(!is_null($this->joinTableName)) {
     //TableRegistry::remove($this->joinTableName);
     //TableRegistry::get($this->joinTableName, ['connection' => ConnectionManager::get('test')]);
     //}
 }
开发者ID:bostontrader,项目名称:duncemaster,代码行数:34,代码来源:DMFixture.php

示例10: index

    public function index()
    {
        $conn = ConnectionManager::get('default');
        //Create gallery
        $query = 'CREATE TABLE gallery (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    category_id INT(11),
    title VARCHAR(50),
    description TEXT,
    img VARCHAR(50),
    created DATETIME DEFAULT NULL,
    modified DATETIME DEFAULT NULL
)';
        $conn->query($query);
        //Create gallery categories
        $query = 'CREATE TABLE category (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(50),
    description TEXT,
    img VARCHAR(50),
    created DATETIME DEFAULT NULL,
    modified DATETIME DEFAULT NULL
)';
        $conn->query($query);
        $this->Flash->success('Successfully installed.');
        return $this->redirect(['controller' => 'category', 'action' => 'index']);
    }
开发者ID:brnagn7,项目名称:grainslive,代码行数:27,代码来源:InstallController.php

示例11: add

 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add($crisis_id = null)
 {
     if ($this->Infos->find('all')->count() === 0) {
         ConnectionManager::get('default')->execute('ALTER TABLE infos AUTO_INCREMENT 1');
     }
     if ($crisis_id != null) {
         $user_id = $this->Auth->user()['id'];
         $info = $this->Infos->newEntity();
         if ($this->request->is('post')) {
             $info->crisis_id = $crisis_id;
             $info->user_id = $user_id;
             $info = $this->Infos->patchEntity($info, $this->request->data);
             if ($this->Infos->save($info)) {
                 $this->Flash->success(__('L\'information a bien été enregistrée.'));
                 return $this->redirect(['controller' => 'crisis', 'action' => 'view', $crisis_id]);
             } else {
                 $this->Flash->error(__('L\'information n\'a pas pu être enregistrée.'));
             }
         }
         $Crisis = $this->Infos->Crisis->find('list', ['limit' => 200]);
         $users = $this->Infos->Users->find('list', ['limit' => 200]);
         $this->set(compact('info', 'Crisis', 'users', 'crisis_id'));
         $this->set('_serialize', ['info']);
     } else {
         $this->Flash->error(__('Vous devez spécifier la crise liée à cette information.'));
         return $this->redirect(['controller' => 'Homes', 'action' => 'index']);
     }
 }
开发者ID:agourd,项目名称:dev-fsociety,代码行数:33,代码来源:InfosController.php

示例12: add

 public function add()
 {
     $palestrante = $this->Palestrantes->newEntity();
     if ($this->request->is('post')) {
         if (is_uploaded_file($this->request->data['foto']['tmp_name'])) {
             $filename = $this->request->data['foto']['name'];
             $ext = pathinfo($filename, PATHINFO_EXTENSION);
             while (true) {
                 $filename = uniqid(rand(), true) . '.' . $ext;
                 if (!'imagestore/' . $filename) {
                     break;
                 }
             }
             move_uploaded_file($this->request->data['foto']['tmp_name'], 'imagestore/' . $filename);
             // store the filename in the array to be saved to the db
             $this->request->data['foto'] = $filename;
         }
         $palestrante = $this->Palestrantes->patchEntity($palestrante, $this->request->data);
         if ($this->Palestrantes->save($palestrante)) {
             $this->Flash->default(__('Palestrante adicionado com sucesso'));
             return $this->redirect(['action' => 'view', $palestrante->id]);
         }
         $this->Flash->error(__('Incrição não realizada, verifique se preencheu o formulário corretamente!'));
     }
     $connection = ConnectionManager::get('default');
     $result = $connection->execute('SELECT id, nome FROM users')->fetchAll('assoc');
     $usersList = array();
     $usersList[null] = 'Selecione';
     foreach ($result as $row) {
         $usersList[$row['id']] = $row['nome'];
     }
     $this->set('usersList', $usersList);
     $this->set('palestrante', $palestrante);
 }
开发者ID:AlexandreSGV,项目名称:siteentec,代码行数:34,代码来源:PalestrantesController.php

示例13: insert

 public function insert(UploadDTO\CustomerFeedbackUploadDto $customerFeedback, $userInfo)
 {
     $conn = ConnectionManager::get('default');
     $conn->begin();
     $tableObj = $this->connect();
     $customerFeedbackCounter = 0;
     try {
         foreach ($customerFeedback->feedback as $feedback) {
             $newCustomerFeedback = $tableObj->newEntity();
             $newCustomerFeedback->CustId = $customerFeedback->custId;
             $newCustomerFeedback->UserId = $userInfo->userId;
             $newCustomerFeedback->FeedbackId = $feedback->feedbackId;
             $newCustomerFeedback->FeedbackRating = $feedback->feedbackRating;
             $newCustomerFeedback->CreatedDate = date(VB_DATE_TIME_FORMAT);
             if ($tableObj->save($newCustomerFeedback)) {
                 $customerFeedbackCounter++;
             } else {
                 $customerFeedbackCounter = 0;
             }
         }
     } catch (Exception $ex) {
         $conn->rollback();
         return $customerFeedbackCounter;
     }
     if ($customerFeedbackCounter) {
         $conn->commit();
         return $customerFeedbackCounter;
     }
 }
开发者ID:Vibeosys,项目名称:RorderWeb,代码行数:29,代码来源:CustomerFeedbackTable.php

示例14: testWithPreMadeConnection

 public function testWithPreMadeConnection()
 {
     ConnectionManager::config('default', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite']);
     $module = new CakeDbModule('default');
     $instance = (new Injector($module, $_ENV['TMP_DIR']))->getInstance('Cake\\Database\\Connection');
     $this->assertSame(ConnectionManager::get('default'), $instance);
 }
开发者ID:kumamidori,项目名称:Ray.CakeDbModule,代码行数:7,代码来源:CakeDbModuleTest.php

示例15: getTotalInvoicesByPo

 public function getTotalInvoicesByPo($data)
 {
     $connection = ConnectionManager::get('default');
     $results = $connection->execute('select sum(invoice_users.total) total from invoices,invoice_users where invoices.id=invoice_users.invoice_id and invoices.po_id=' . $data['po_id'])->fetchAll();
     $this->log(print_r($results, true), 'debug');
     return array('sum' => $results[0][0]);
 }
开发者ID:vasudevan-palani,项目名称:minion,代码行数:7,代码来源:InvoicesComponent.php


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