本文整理汇总了PHP中Cake\Datasource\ConnectionManager类的典型用法代码示例。如果您正苦于以下问题:PHP ConnectionManager类的具体用法?PHP ConnectionManager怎么用?PHP ConnectionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConnectionManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: install
public function install()
{
$sql = [];
$defaultSql = ['40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT', '40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS', '40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION', '40101 SET NAMES utf8', '40103 SET @OLD_TIME_ZONE=@@TIME_ZONE', '40103 SET TIME_ZONE=\'+00:00\'', '40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0', '40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0', '40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO\'', '40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0'];
foreach ($defaultSql as $key => $value) {
$sql[] = '/*!' . $value . ' */;';
}
$sql[] = "\n";
$db = ConnectionManager::get('default');
$collection = $db->schemaCollection();
$tables = $collection->listTables();
if (count($tables) > 0) {
foreach ($tables as $key => $value) {
$table = $collection->describe($value)->createSql($db);
$sql[] = '-- Inicio das estrutura da tabela `' . $value . '` --';
$sql[] = '/* !40101 SET character_set_client = utf8 */;';
$sql[] = 'DROP TABLE IF EXISTS `' . $value . '`;';
$sql[] = str_replace('CREATE TABLE ', 'CREATE TABLE IF NOT EXISTS ', $table[0]) . ';';
$sql[] = '-- Fim das estrutura da tabela `' . $value . '` --';
$sql[] = "\n";
}
}
$defaultSql = ['40101 SET SQL_MODE=@OLD_SQL_MODE', '40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS', '40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS', '40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT', '40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS', '40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION', '40111 SET SQL_NOTES=@OLD_SQL_NOTES'];
foreach ($defaultSql as $key => $value) {
$sql[] = '/* !' . $value . ' */;';
}
$sql[] = "\n";
$this->save('kiterp.sql', $sql);
}
开发者ID:lucasnpinheiro,项目名称:Kiterp,代码行数:29,代码来源:GerarSqlShell.php
示例17: add
/**
* Add method
*
* @return void Redirects on successful add, renders view otherwise.
*/
public function add()
{
if ($this->Crisis->find('all')->count() === 0) {
ConnectionManager::get('default')->execute('ALTER TABLE crisis AUTO_INCREMENT 1');
}
$crisi = $this->Crisis->newEntity();
if (isset($this->request->data)) {
$crisi = $this->Crisis->patchEntity($crisi, $this->request->data);
//do magic here
$crisis = $this->Crisis->find('all');
$delta_search = 0.5;
foreach ($crisis as $crisi_db) {
if (abs($crisi_db['latitude'] - $crisi['latitude']) < $delta_search && abs($crisi_db['latitude'] - $crisi['latitude']) < $delta_search && $crisi_db->state != 'over') {
//1° lat/long-> 111 km
$crisi_db->severity += 1;
if ($this->Crisis->save($crisi_db)) {
$this->Flash->success('Cette crise a déjà été signalée, nous incrémentons sa gravité.');
} else {
$this->Flash->error('La crise n\'a pas pu être enregistrée.');
}
return $this->redirect(['controller' => 'Homes', 'action' => 'index']);
}
}
if ($this->Crisis->save($crisi)) {
$this->Flash->success(__('La crise a bien été enregistrée.'));
} else {
$this->Flash->error(__('La crise n\'a pas pu être enregistrée.'));
}
return $this->redirect(['controller' => 'Homes', 'action' => 'index']);
}
}
开发者ID:agourd,项目名称:dev-fsociety,代码行数:36,代码来源:CrisisController.php
示例18: main
/**
* Override main() to handle action
*
* @return mixed
*/
public function main()
{
if ($this->args && $this->args[0] === 'view') {
$this->out('<error>The view command has been renamed.</error>');
$this->out('To create template files, please use the template command:', 2);
$args = $this->args;
array_shift($args);
$args = implode($args, ' ');
$this->out(sprintf(' <info>`bin/cake bake template %s`</info>', $args), 2);
return false;
}
$connections = ConnectionManager::configured();
if (empty($connections)) {
$this->out('Your database configuration was not found.');
$this->out('Add your database connection information to config/app.php.');
return false;
}
$this->out('The following commands can be used to generate skeleton code for your application.', 2);
$this->out('<info>Available bake commands:</info>', 2);
$this->out('- all');
$names = [];
foreach ($this->tasks as $task) {
list(, $name) = pluginSplit($task);
$names[] = Inflector::underscore($name);
}
sort($names);
foreach ($names as $name) {
$this->out('- ' . $name);
}
$this->out('');
$this->out('By using <info>`cake bake [name]`</info> you can invoke a specific bake task.');
return false;
}
开发者ID:webroup17,项目名称:social_networking,代码行数:38,代码来源:BakeShell.php
示例19: setUp
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->Addresses = TableRegistry::get('Geo.Addresses');
$this->Addresses->addBehavior('Geo.Geocoder', array('real' => false));
$this->db = ConnectionManager::get('test');
}
开发者ID:surjit,项目名称:cakephp-geo,代码行数:12,代码来源:GeocoderBehaviorTest.php
示例20: imageHelper
/**
* Returns the TMDB image helper from the API wrapper.
*
* @return object Image helper
*/
public function imageHelper()
{
$tmdb = \Cake\Datasource\ConnectionManager::get('Tmdb');
$configRepository = new \Tmdb\Repository\ConfigurationRepository($tmdb->getClient());
$config = $configRepository->load();
return new \Tmdb\Helper\ImageHelper($config);
}
开发者ID:drmonkeyninja,项目名称:cakephp-tmdb,代码行数:12,代码来源:TmdbHelper.php
注:本文中的Cake\Datasource\ConnectionManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论