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


PHP Table::save方法代码示例

本文整理汇总了PHP中Cake\ORM\Table::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::save方法的具体用法?PHP Table::save怎么用?PHP Table::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\ORM\Table的用法示例。


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

示例1: testUnaryExpression

 /**
  * test WHERE conditions against unary expression.
  *
  * @return void
  */
 public function testUnaryExpression()
 {
     $this->table->addColumn('user-birth-date', ['type' => 'date'], false);
     $first = $this->table->get(1);
     $first->set('user-birth-date', time());
     $this->table->save($first);
     $second = $this->table->find('all', ['eav' => true])->where(['user-birth-date IS' => null])->order(['id' => 'ASC'])->first();
     $this->assertTrue(!empty($second) && $second->get('id') == 2);
 }
开发者ID:quickapps-plugins,项目名称:eav,代码行数:14,代码来源:EavBehaviorTest.php

示例2: saveSettingsAction

 public function saveSettingsAction()
 {
     try {
         $this->cronSettings->save($this->cronSettings->get(1)->set($_POST));
         $this->flasher->success('Saved general cron settings!');
     } catch (\Exception $e) {
         $this->flasher->error("Could not save general cron settings: " . $e->getMessage());
     }
     $this->redirect('/admin/crons');
 }
开发者ID:Swader,项目名称:nofw,代码行数:10,代码来源:CronController.php

示例3: resetSlugs

 /**
  * ResetSlugs method.
  *
  * Regenerate all slugs. On large dbs this can take more than 30 seconds - a time
  * limit is set to allow a minimum 100 updates per second as a preventative measure.
  *
  * Note that you should use the Reset behavior if you need additional functionality such
  * as callbacks or timeouts.
  *
  * @param array $params
  * @return bool Success
  */
 public function resetSlugs($params = [])
 {
     if (!$this->_table->hasField($this->_config['field'])) {
         throw new Exception('Table does not have field ' . $this->_config['field']);
     }
     $defaults = ['page' => 1, 'limit' => 100, 'fields' => array_merge([$this->_table->primaryKey()], $this->_config['label']), 'order' => $this->_table->displayField() . ' ASC', 'conditions' => $this->_config['scope'], 'overwrite' => true];
     $params = array_merge($defaults, $params);
     $count = $this->_table->find('all', compact('conditions'))->count();
     $max = ini_get('max_execution_time');
     if ($max) {
         set_time_limit(max($max, $count / 100));
     }
     $this->_table->behaviors()->Slugged->config($params, null, false);
     while ($records = $this->_table->find('all', $params)->toArray()) {
         foreach ($records as $record) {
             $record->isNew(true);
             $options = ['validate' => true, 'fieldList' => array_merge([$this->_table->primaryKey(), $this->_config['field']], $this->_config['label'])];
             if (!$this->_table->save($record, $options)) {
                 throw new Exception(print_r($this->_table->errors(), true));
             }
         }
         $params['page']++;
     }
     return true;
 }
开发者ID:dereuromark,项目名称:cakephp-tools,代码行数:37,代码来源:SluggedBehavior.php

示例4: testSave

 /**
  * testSave
  *
  * @retun void
  * @access public
  */
 public function testSave()
 {
     $data = ['nome' => 'Produto 4', 'valor' => '5.000,00'];
     $entidade = $this->Produtos->newEntity($data);
     $resultado = $this->Produtos->save($entidade);
     $this->assertInstanceOf('Cake\\ORM\\Entity', $resultado);
     $this->assertEquals('5000.00', $entidade->get("valor"));
     $this->assertEquals('5000.00', $resultado->get("valor"));
 }
开发者ID:matheusviegas,项目名称:cake_ptbr,代码行数:15,代码来源:AjusteFloatBehaviorTest.php

示例5: __preparaNoticia

 /**
  *
  * @param bool $publicadoEm Valor para colocar no publicado_em
  * @param bool $autorizadoEm Valor para colocar no autorizado_em
  * @return \Cake\Datasource\EntityInterface|mixed
  */
 private function __preparaNoticia($publicadoEm = false, $autorizadoEm = false)
 {
     $noticia = $this->Noticias->newEntity(['titulo' => 'Exemplo 1', 'conteudo' => 'Exemplo exemplo', 'autor_id' => 2, 'publicado_em' => '2011-04-21 16:42:05', 'autorizado_em' => '2011-04-21']);
     $noticia->set("autorizado_em", $autorizadoEm ?: "22/03/2015");
     $noticia->set("publicado_em", $publicadoEm ?: "25/03/2015 16:42:05");
     $this->Noticias->save($noticia);
     $this->assertEmpty($noticia->errors());
     return $noticia;
 }
开发者ID:matheusviegas,项目名称:cake_ptbr,代码行数:15,代码来源:AjusteDataBehaviorTest.php

示例6: testSaveReplaceSaveStrategyAdding

 /**
  * Test that the associated entities are unlinked and deleted when they have a not nullable foreign key
  *
  * @return void
  */
 public function testSaveReplaceSaveStrategyAdding()
 {
     $articles = new Table(['table' => 'articles', 'alias' => 'Articles', 'connection' => $this->connection, 'entityClass' => 'Cake\\ORM\\Entity']);
     $articles->hasMany('Comments', ['saveStrategy' => 'replace']);
     $article = $articles->newEntity(['title' => 'Bakeries are sky rocketing', 'body' => 'All because of cake', 'comments' => [['user_id' => 1, 'comment' => 'That is true!'], ['user_id' => 2, 'comment' => 'Of course']]], ['associated' => ['Comments']]);
     $article = $articles->save($article, ['associated' => ['Comments']]);
     $commentId = $article->comments[0]->id;
     $sizeComments = count($article->comments);
     $articleId = $article->id;
     $this->assertEquals($sizeComments, $articles->Comments->find('all')->where(['article_id' => $article->id])->count());
     $this->assertTrue($articles->Comments->exists(['id' => $commentId]));
     unset($article->comments[0]);
     $article->comments[] = $articles->Comments->newEntity(['user_id' => 1, 'comment' => 'new comment']);
     $article->dirty('comments', true);
     $article = $articles->save($article, ['associated' => ['Comments']]);
     $this->assertEquals($sizeComments, $articles->Comments->find('all')->where(['article_id' => $article->id])->count());
     $this->assertFalse($articles->Comments->exists(['id' => $commentId]));
     $this->assertTrue($articles->Comments->exists(['to_char(comment)' => 'new comment', 'article_id' => $articleId]));
 }
开发者ID:cakedc,项目名称:cakephp-oracle-driver,代码行数:24,代码来源:TableTest.php

示例7: write

 /**
  * Helper function called on write for database sessions.
  *
  * @param int $id ID that uniquely identifies session in database
  * @param mixed $data The value of the data to be saved.
  * @return bool True for successful write, false otherwise.
  */
 public function write($id, $data)
 {
     if (!$id) {
         return false;
     }
     $expires = time() + $this->_timeout;
     $record = compact('data', 'expires');
     $record[$this->_table->primaryKey()] = $id;
     $result = $this->_table->save(new Entity($record));
     return (bool) $result;
 }
开发者ID:thanghexp,项目名称:project,代码行数:18,代码来源:DatabaseSession.php

示例8: getDraftId

 /**
  * Find or create new draft database entry and return entity ID
  * 
  * @param \Cake\ORM\Table $table      Table instance
  * @param array|null      $conditions Find conditions
  *
  * @return int             $id         Draft Id
  */
 public function getDraftId(Table $table, $conditions = [])
 {
     $conditions = array_merge($this->config[$table->alias()]['conditions'], $conditions);
     $result = $table->find()->select(['id' => $table->primaryKey()])->andWhere($conditions)->first();
     if ($result) {
         return $result->id;
     } else {
         $entity = $table->newEntity($conditions, ['validate' => false]);
         $entity = $table->save($entity);
         return $entity->id;
     }
 }
开发者ID:romano83,项目名称:cakephp3-draft,代码行数:20,代码来源:DraftBehavior.php

示例9: fieldToggle

 /**
  * Toggle field value.
  *
  * @param Table|\Cake\ORM\Table $table
  * @param string|int $id
  * @param string|int $value
  * @param string $field
  * @throw BadRequestException
  * @throw RuntimeException
  */
 public function fieldToggle($table, $id, $value, $field = self::TOGGLE_DEFAULT_FIELD)
 {
     $this->_checkIsAjax();
     $this->_checkToggleData($id, $value);
     $this->_controller->viewBuilder()->layout('ajax')->templatePath('Common');
     $entity = $table->get($id);
     $entity->{$field} = !(int) $value;
     if ($result = $table->save($entity)) {
         $this->_controller->set('record', $result);
         $this->_controller->render('toggle');
     } else {
         throw new RuntimeException(__d('union', 'Failed toggling field {0} to {1}', $field, $entity->{$field}));
     }
 }
开发者ID:UnionCMS,项目名称:Core,代码行数:24,代码来源:AppComponent.php

示例10: testGenerateWithAutoPathAndHideUnrelatedAndSiblings

    /**
     * - One
     * -- One-SubA
     * - Two
     * -- Two-SubA
     * --- Two-SubA-1
     * ---- Two-SubA-1-1
     * -- Two-SubB
     * -- Two-SubC
     * - Three
     * - Four
     * -- Four-SubA
     *
     * @return void
     */
    public function testGenerateWithAutoPathAndHideUnrelatedAndSiblings()
    {
        $this->skipIf(true, 'FIXME');
        $data = [['name' => 'Two-SubB', 'parent_id' => 2], ['name' => 'Two-SubC', 'parent_id' => 2]];
        foreach ($data as $row) {
            $row = new Entity($row);
            $this->Table->save($row);
        }
        $tree = $this->Table->find('threaded')->toArray();
        $id = 6;
        $nodes = $this->Table->find('path', ['for' => $id]);
        $path = $nodes->extract('id')->toArray();
        $output = $this->Tree->generate($tree, ['autoPath' => [6, 11], 'hideUnrelated' => true, 'treePath' => $path, 'callback' => [$this, '_myCallbackSiblings']]);
        // Two-SubA
        //debug($output);
        $expected = <<<TEXT

<ul>
\t<li>One (sibling)</li>
\t<li class="active">Two (active)
\t<ul>
\t\t<li class="active">Two-SubA (active)
\t\t<ul>
\t\t\t<li>Two-SubA-1</li>
\t\t</ul>
\t\t</li>
\t\t<li>Two-SubB</li>
\t\t<li>Two-SubC</li>
\t</ul>
\t</li>
\t<li>Three (sibling)</li>
\t<li>Four (sibling)</li>
</ul>

TEXT;
        $output = str_replace(["\t", "\r", "\n"], '', $output);
        $expected = str_replace(["\t", "\r", "\n"], '', $expected);
        //debug($output);
        //debug($expected);
        $this->assertTextEquals($expected, $output);
    }
开发者ID:alescx,项目名称:cakephp-tools,代码行数:56,代码来源:TreeHelperTest.php

示例11: _removeFromTree

 /**
  * Helper function containing the actual code for removeFromTree
  *
  * @param \Cake\ORM\Entity $node The node to remove from the tree
  * @return \Cake\ORM\Entity|false the node after being removed from the tree or
  * false on error
  */
 protected function _removeFromTree($node)
 {
     $config = $this->config();
     $left = $node->get($config['left']);
     $right = $node->get($config['right']);
     $parent = $node->get($config['parent']);
     $node->set($config['parent'], null);
     if ($right - $left == 1) {
         return $this->_table->save($node);
     }
     $primary = $this->_table->primaryKey();
     $this->_table->updateAll([$config['parent'] => $parent], [$config['parent'] => $node->get($primary)]);
     $this->_sync(1, '-', 'BETWEEN ' . ($left + 1) . ' AND ' . ($right - 1));
     $this->_sync(2, '-', "> {$right}");
     $edge = $this->_getMax();
     $node->set($config['left'], $edge + 1);
     $node->set($config['right'], $edge + 2);
     $fields = [$config['parent'], $config['left'], $config['right']];
     $this->_table->updateAll($node->extract($fields), [$primary => $node->get($primary)]);
     foreach ($fields as $field) {
         $node->dirty($field, false);
     }
     return $node;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:31,代码来源:TreeBehavior.php

示例12: testReplaceHasManyNoPersistedEntities

 /**
  * Integration test for replacing entities with HasMany and no already persisted entities. The transaction must be successfull.
  * Replace operation should prevent considering 0 changed records an error when they are not found in the table
  *
  * @return void
  */
 public function testReplaceHasManyNoPersistedEntities()
 {
     $authors = new Table(['connection' => $this->connection, 'alias' => 'Authors', 'table' => 'authors']);
     $authors->hasMany('Articles');
     $author = $authors->newEntity(['name' => 'mylux']);
     $author = $authors->save($author);
     $newArticles = $authors->Articles->newEntities([['title' => 'New bakery next corner', 'body' => 'They sell tastefull cakes'], ['title' => 'Spicy cake recipe', 'body' => 'chocolate and peppers']]);
     $authors->Articles->deleteAll(['1=1']);
     $sizeArticles = count($newArticles);
     $this->assertTrue($authors->Articles->link($author, $newArticles));
     $this->assertEquals($authors->Articles->findAllByAuthorId($author->id)->count(), $sizeArticles);
     $this->assertEquals(count($author->articles), $sizeArticles);
     $this->assertTrue($authors->Articles->replace($author, $newArticles));
     $this->assertCount($sizeArticles, $authors->Articles->findAllByAuthorId($author->id));
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:21,代码来源:TableTest.php

示例13: _process

 /**
  * Processes the records.
  *
  * @param \Cake\ORM\Table $table
  * @param int $chunkCount
  * @param int $chunkSize
  * @return void
  */
 protected function _process(Table $table, $chunkCount, $chunkSize)
 {
     $query = $table->find();
     if ($table->hasFinder('purifier')) {
         $query->find('purifier');
     }
     $fields = explode(',', $this->param('fields'));
     $fields[] = $table->primaryKey();
     $results = $query->select($fields)->offset($chunkCount)->limit($chunkSize)->orderDesc($table->aliasField($table->primaryKey()))->all();
     if (empty($results)) {
         return;
     }
     foreach ($results as $result) {
         try {
             $table->save($result);
             $chunkCount++;
         } catch (\Exception $e) {
             $this->error($e->getMessage());
         }
     }
 }
开发者ID:burzum,项目名称:cakephp-html-purifier,代码行数:29,代码来源:PurifierShell.php

示例14: importTable

 /**
  * Helper function to import a set of records for a single Table.
  *
  * Used by imporTables().
  *
  * @param Cake\ORM\Table $Table A Table instance to save records into.
  * @param array $records An array of Entity records to save into the Table.
  * @return void
  */
 public function importTable(Table $Table, $records)
 {
     foreach ($records as $record) {
         $result = $Table->save($record);
         $key = $this->findKey($Table, $record);
         if ($result) {
             $this->out("{$Table->alias()} ({$key}): Save successful.");
         } else {
             $this->out("{$Table->alias()} ({$key}): <warning>Save failed.</warning>");
         }
     }
 }
开发者ID:klickagent,项目名称:CakePHP-Basic-Seed,代码行数:21,代码来源:BasicSeedShell.php

示例15: save

 /**
  * Save record data in database.
  *
  * @param EntityInterface $entity
  * @param array $options
  * @return bool|EntityInterface|mixed|\Union\Core\ORM\Entity
  */
 public function save(EntityInterface $entity, $options = [])
 {
     return parent::save($entity, $options);
 }
开发者ID:UnionCMS,项目名称:Core,代码行数:11,代码来源:Table.php


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