本文整理汇总了PHP中Cake\ORM\Table::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::get方法的具体用法?PHP Table::get怎么用?PHP Table::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Table
的用法示例。
在下文中一共展示了Table::get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSendNewPasswordEmail
/**
* testSendNewPasswordEmail
*
* @return void
*/
public function testSendNewPasswordEmail()
{
$user = $this->Users->get(1);
$this->Mailer->expects($this->once())->method('to')->with('adminuser@testuser.com')->will($this->returnSelf());
$this->Mailer->expects($this->once())->method('subject')->with('Your new password')->will($this->returnSelf());
$this->Mailer->expects($this->once())->method('template')->with('Burzum/UserTools.Users/new_password')->will($this->returnSelf());
$this->Mailer->expects($this->once())->method('set')->with('user', $user)->will($this->returnSelf());
$this->Mailer->sendNewPasswordEmail($user);
}
示例2: 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);
}
示例3: moveNode
/**
* Move a node under the same parent node or under a new node.
* New position of the node can be specified
*
* @param int $id ID of the node to move
* @param int $parent_id ID of the (new) parent node
* @param int $position New position of the node. Position is zero based.
* @return boolean
*/
public function moveNode($id, $parent_id, $position = null)
{
$primaryKey = $this->_table->schema()->primaryKey();
$primaryKey = count($primaryKey) == 1 ? $primaryKey[0] : $primaryKey;
$parent_id_fieldname = $this->config('model_parent_id_fieldname');
$sort_fieldname = $this->config('model_sort_fieldname');
$connection = $this->_table->connection();
$connection->begin();
$result = true;
/*
* Get moved node
*/
$node = $this->_table->get($id);
/*
* Get current nodes positions of (new) siblings
*/
$current_children = $this->_table->query()->where([$parent_id_fieldname => $parent_id])->order([$sort_fieldname => 'asc']);
$new_sort_children = [];
foreach ($current_children as $current_position => $current_child) {
if ($current_child->{$primaryKey} != $id) {
$new_sort_children[] = $current_child;
}
}
/*
* Default position is after all siblings
*/
$position = isset($position) ? $position : $current_children->count();
$position = $position >= 0 ? $position : 0;
$position = $position <= count($new_sort_children) ? $position : count($new_sort_children);
/*
* Insert moved node at position
*/
array_splice($new_sort_children, $position, 0, array($node));
/*
* If node has a new parent -> save it
*/
if ($node->{$parent_id_fieldname} != $parent_id) {
$query = $this->_table->query()->update()->set([$parent_id_fieldname => $parent_id])->where([$primaryKey => $id]);
if (!$query->execute()) {
$result = false;
}
}
/*
* Update positions
*/
foreach ($new_sort_children as $index => $new_sort_child) {
$query = $this->_table->query()->update()->set([$sort_fieldname => $index * 10])->where([$primaryKey => $new_sort_child->{$primaryKey}]);
if (!$query->execute()) {
$result = false;
}
}
/***********/
if ($result) {
$connection->commit();
} else {
$connection->rollback();
}
return $result;
}
示例4: testGET_view
public function testGET_view()
{
// 1. Obtain the relevant records and verify their referential integrity.
$book_id = FixtureConstants::bookTypical;
$distribution_id = FixtureConstants::distributionTypical;
$distribution = $this->Distributions->get($distribution_id, ['contain' => ['Accounts.Categories', 'Currencies']]);
$transaction_id = FixtureConstants::transactionTypical;
$transaction = $this->Transactions->get($transaction_id);
$this->assertEquals($distribution['transaction_id'], $transaction['id']);
// 2. Submit request, examine response, observe no redirect, and parse the response.
$this->get("/books/{$book_id}/transactions/{$transaction_id}/distributions/{$distribution_id}");
$this->assertResponseCode(200);
$this->assertNoRedirect();
$dom = new \DomDocument();
$dom->loadHTML($this->_response->body());
$xpath = new \DomXPath($dom);
// 3. Isolate the content produced by this controller method (excluding the layout.)
$content_node = $this->getTheOnlyOne($xpath, "//div[@id='DistributionsView']");
// 4. Count the A tags.
$unknownATagCnt = $xpath->query(".//a", $content_node)->length;
// 4.1 Look for the account distributions link
//$this->getTheOnlyOne($xpath,"//a[@id='AccountDistributions']",$content_node);
//$unknownATagCnt--;
// 4.2 Ensure that all the <A> tags have been accounted for
$this->assertEquals(0, $unknownATagCnt);
// 5. Ensure that there is a suitably named table to display the results.
$table_node = $this->getTheOnlyOne($xpath, "//table[@id='DistributionViewTable']", $content_node);
// 5.1 Inspect the caption of the table.
$this->assertContains("{$distribution_id}", $this->getTheOnlyOne($xpath, "caption", $table_node)->textContent);
// 6. Now inspect the fields in the table. We want to know that:
// A. The correct fields are there and no other fields.
// B. The fields have correct values.
//
// This is the count of the table rows that are presently unaccounted for.
$unknownRowCnt = $xpath->query("//tr", $table_node)->length;
// 6.1 drcr
$expected = $distribution['drcr'] == 1 ? 'DR' : 'CR';
$this->getTheOnlyOne($xpath, "//tr[1][@id='drcr']/td[text()='{$expected}']", $table_node);
$unknownRowCnt--;
// 6.2 category_title
$expected = $distribution->account->catstring;
$this->getTheOnlyOne($xpath, "//tr[2][@id='category_title']/td[text()='{$expected}']", $table_node);
$unknownRowCnt--;
// 6.3 account title
$expected = $distribution->account->title;
$this->getTheOnlyOne($xpath, "//tr[3][@id='account_title']/td[text()='{$expected}']", $table_node);
$unknownRowCnt--;
// 6.4 amount
$this->getTheOnlyOne($xpath, "//tr[4][@id='amount']/td[text()='{$distribution->amount}']", $table_node);
$unknownRowCnt--;
// 6.5 currency symbol
$expected = $distribution->currency->symbol;
$this->getTheOnlyOne($xpath, "//tr[5][@id='currency_symbol']/td[text()='{$expected}']", $table_node);
$unknownRowCnt--;
// 6.9 Have all the rows been accounted for? Are there any extras?
$this->assertEquals(0, $unknownRowCnt);
}
示例5: get
/**
* Fetch a setting by keys
* @param string $key
* @param array $options
* @return string
*/
public function get($key, $options = [])
{
try {
$setting = parent::get($key, $options);
return (string) $setting;
} catch (\Cake\Datasource\Exception\RecordNotFoundException $ex) {
return '';
}
}
示例6: deleteCronAction
public function deleteCronAction()
{
$id = $_POST['id'] ?? null;
if ($id) {
try {
$cron = $this->cronsTable->get($id);
if (($_POST['deleteLog'] ?? false) == $id && $cron->output) {
$logFile = $this->site['logFolder'] . '/' . $cron->output;
if (!unlink($logFile)) {
$this->flasher->error("Could not delete log file: " . $logFile);
}
}
$this->cronsTable->delete($cron);
$this->flasher->success('Successfully deleted cron!');
} catch (\Exception $e) {
$this->flasher->error("Could not delete cron: " . $e->getMessage());
}
$this->redirect('/admin/crons');
}
}
示例7: _ensureFields
/**
* Ensures that the provided entity contains non-empty values for the left and
* right fields
*
* @param \Cake\ORM\Entity $entity The entity to ensure fields for
* @return void
*/
protected function _ensureFields($entity)
{
$config = $this->config();
$fields = [$config['left'], $config['right']];
$values = array_filter($entity->extract($fields));
if (count($values) === count($fields)) {
return;
}
$fresh = $this->_table->get($entity->get($this->_table->primaryKey()), $fields);
$entity->set($fresh->extract($fields), ['guard' => false]);
foreach ($fields as $field) {
$entity->dirty($field, false);
}
}
示例8: 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}));
}
}
示例9: testGetExceptionOnTooMuchData
/**
* Test that an exception is raised when there are too many keys.
*
* @expectedException Cake\Datasource\Exception\InvalidPrimaryKeyException
* @expectedExceptionMessage Record not found in table "articles" with primary key [1, 'two']
* @return void
*/
public function testGetExceptionOnTooMuchData()
{
$table = new Table(['name' => 'Articles', 'connection' => $this->connection, 'table' => 'articles']);
$table->get([1, 'two']);
}
示例10: get
/**
* Get an article and some relationships:
*
* @param mixed $primaryKey
* @param array $options
* @return \Union\Core\ORM\Entity
*/
public function get($primaryKey, $options = [])
{
return parent::get($primaryKey, $options);
}
示例11: testGetExceptionOnIncorrectData
/**
* Test that an exception is raised when there are not enough keys.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Incorrect number of primary key values. Expected 1 got 0.
* @return void
*/
public function testGetExceptionOnIncorrectData()
{
$table = new Table(['name' => 'Articles', 'connection' => $this->connection, 'table' => 'articles']);
$table->get(null);
}
示例12: fieldToggle
/**
* Toggle ajax field.
*
* @param Table $table
* @param $id
* @param $value
* @param string $field
*/
public function fieldToggle(Table $table, $id, $value, $field = 'status')
{
$this->_controller->serializeAjax = false;
if (empty($id) || $value === null) {
throw new Exception(__d('union', 'Invalid content'));
}
$this->_controller->viewBuilder()->layout('ajax')->templatePath('Common');
$record = $table->get($id);
$record->{$field} = (int) (!$value);
if ($entity = $table->save($record)) {
$this->_controller->set('record', $entity);
$this->_controller->render('Union/Core.toggle');
} else {
throw new Exception(__d('union', 'Failed toggling field {0} to {1}', $field, $record->{$field}));
}
}