本文整理汇总了PHP中Cake\ORM\TableRegistry类的典型用法代码示例。如果您正苦于以下问题:PHP TableRegistry类的具体用法?PHP TableRegistry怎么用?PHP TableRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TableRegistry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: afterCasAuthenticate
public function afterCasAuthenticate(Event $event)
{
$user = $event->data();
if (empty($user['username'])) {
return null;
}
if (!array_key_exists('id', $user)) {
$user['id'] = $user['username'];
}
$localUser = TableRegistry::get('Users')->findOrCreateByNetid($user['username'], true);
//force PersonSummary update check
if (empty($localUser)) {
return null;
}
$user['id'] = $localUser->id;
if (empty($user['name']) && !empty($localUser->name)) {
$user['name'] = $localUser->name;
}
if (empty($user['byuId']) && !empty($localUser->byu_id)) {
$user['byuId'] = $localUser->byu_id;
}
$user['officers'] = TableRegistry::get('Officers')->listUserActive($localUser->id);
$user['advisors'] = TableRegistry::get('Advisors')->listUserApproved($localUser->id);
$user['members'] = TableRegistry::get('Members')->listActiveClubs($localUser->id);
$user['roles'] = TableRegistry::get('Roles')->listByUser($localUser->id);
$user['roles']['dean'] = TableRegistry::get('Departments')->listByDean($user['username']);
$homePrefixes = ['admin', 'dean', 'risk', 'review'];
//roles that have a default home, in descending preference order
foreach ($homePrefixes as $prefix) {
if (!empty($user['roles'][$prefix])) {
$user['default_home'] = ['prefix' => $prefix, 'controller' => 'clubs', 'action' => 'index'];
}
}
return $user;
}
开发者ID:byu-oit-appdev,项目名称:byusa-clubs,代码行数:35,代码来源:AppController.php
示例2: _buildMenus
/**
* Construit les diff�rents menus de la page courante
*/
private function _buildMenus()
{
$host = $this->request->host();
// R�cup�ration du host actuel, ex : www.monsite.fr
$reducer = function ($output, $value) {
$output[0] = $value->locale;
// On ajoute la locale du host
if (!is_null($value->fallback)) {
$output[1] = $value->fallback->locale;
// On ajoute la locale du language de fallback du host
}
return $output;
};
$this->I18ns = TableRegistry::get('BoxManager.I18ns');
$i18ns = $this->I18ns->find('all', ['conditions' => ['OR' => ['I18ns.domain' => $host, 'I18ns.alias' => $host]], 'contain' => ['Fallback']])->reduce($reducer, []);
// @TODO : Revoir la récupération du code menu
$reducer = function ($output, $value) {
$output[MenuTrait::getRawMenu($value->menu_id)] = $value->menuitems;
return $output;
};
$this->Menus = TableRegistry::get("BoxManager.Menus");
$menus = $this->Menus->find('all', ['contain' => ['Menuitems' => function ($query) use($i18ns) {
return $query->find('translations', ['locales' => $i18ns]);
}]])->reduce($reducer, []);
$this->set(compact('menus'));
}
开发者ID:Aerue,项目名称:avalia,代码行数:29,代码来源:ContentbuildersController.php
示例3: index
public function index()
{
$this->autoRender = false;
//array order is important for graph edge hierarchy
$connections = array("HasOne", "HasMany", "BelongsTo", "HasAndBelongsToMany");
$connectionArray = array();
$db = ConnectionManager::get('default');
$collection = $db->schemaCollection();
$tables = $collection->listTables();
foreach ($tables as $table) {
$connectionArray[$table] = [];
foreach ($connections as $edgeRank => $connection) {
$model = TableRegistry::get($table);
echo $table . "<br />";
// debug($model->associations());
foreach ($model->associations() as $key => $association) {
// debug($association);
$class = get_class($association);
$array = explode("\\", $class);
$type = array_pop($array);
echo "<span style='margin-left: 10px;'>" . $type . ": " . $key . "</span><br />";
// if (!empty($connectionArray[$table][$key])) {
// $currentVL = $connectionArray[$table][$key];
// } else {
// $currentVL = 0;
// }
// $connectionArray[$table][$key] = max(array($currentVL, $edgeRank));
}
}
// debug($connectionArray);
// $connectionArray = array_map("unserialize", array_unique(array_map("serialize", $connectionArray)));
// $connectionArray = array_intersect_key($connectionArray, array_unique(array_map('serialize', $connectionArray)));
}
// $this->set(compact('tables', 'connectionArray'));
}
开发者ID:vorien,项目名称:supplyanddemand,代码行数:35,代码来源:ModelMapsController.php
示例4: main
/**
* Adds or drops the specified column.
*
* @return bool
*/
public function main()
{
$options = (array) $this->params;
$options['bundle'] = empty($options['bundle']) ? null : $options['bundle'];
if (empty($options['use'])) {
$this->err(__d('eav', 'You must indicate a table alias name using the "--use" option. Example: "Articles.Users"'));
return false;
}
try {
$table = TableRegistry::get($options['use']);
} catch (\Exception $ex) {
$table = false;
}
if (!$table) {
$this->err(__d('eav', 'The specified table does not exists.'));
return false;
} elseif (!$table->behaviors()->has('Eav')) {
$this->err(__d('eav', 'The specified table is not using EAV behavior.'));
return false;
}
$columns = $table->listColumns($options['bundle']);
ksort($columns, SORT_LOCALE_STRING);
$rows = [[__d('eav', 'Column Name'), __d('eav', 'Data Type'), __d('eav', 'Bundle'), __d('eav', 'Searchable')]];
foreach ($columns as $name => $info) {
$rows[] = [$name, $info['type'], !empty($info['bundle']) ? $info['bundle'] : '---', !empty($info['searchable']) ? 'no' : 'yes'];
}
$this->out();
$this->out(__d('eav', 'EAV information for table "{0}":', $options['use']));
$this->out();
$this->helper('table')->output($rows);
return true;
}
开发者ID:quickapps-plugins,项目名称:eav,代码行数:37,代码来源:InfoTask.php
示例5: update
public function update($id)
{
$orders = TableRegistry::get('Orders');
$query = $orders->query();
$query->update()->set(['complete' => true])->where(['id' => $id])->execute();
return $this->redirect(['action' => 'index']);
}
开发者ID:dimplewraich,项目名称:Assignment-2,代码行数:7,代码来源:OrdersController.php
示例6: beforeFind
public function beforeFind(Event $event, Query $query, $options, $primary)
{
if ($query->clause('limit') == 1) {
return $query;
}
foreach ($this->orderBy() as $field => $ord) {
$f = $this->aliasField($field);
$query->order([$this->aliasField($field) => $ord]);
}
if (!is_array($this->primaryKey())) {
return $query;
}
$query->sql();
// force evaluation of internal state/objects
foreach ($query->clause('join') as $join) {
if (!$this->association($join['table'])) {
continue;
}
$table = TableRegistry::get($join['table']);
$table->alias($join['alias']);
foreach ($table->orderBy() as $field => $ord) {
$query->order([$table->aliasField($field) => $ord]);
}
}
return $query;
}
开发者ID:pwerken,项目名称:va-void,代码行数:26,代码来源:AppTable.php
示例7: saveCart
public function saveCart()
{
$session = $this->request->session();
$user = $session->read('authentication');
$cart = $session->read('my_cart');
if ($user) {
$ordersTable = TableRegistry::get('orders');
$order = $ordersTable->newEntity();
$order->customer_id = $user['customer_id'];
$orderSave = $ordersTable->save($order);
$cart = $session->read('my_cart');
if ($cart) {
$invoicesTable = TableRegistry::get('invoices');
$productsTable = TableRegistry::get('products');
foreach ($cart as $key => $value) {
$product = $productsTable->find('all')->where(['product_id' => $value['product_id']])->first();
$product->qty = $value['qty'] - $value['qty'];
$productsTable->save($product);
$invoice = $invoicesTable->newEntity();
$invoice->order_id = $orderSave->order_id;
$invoice = $invoicesTable->patchEntity($invoice, $value);
$invoicesTable->save($invoice);
}
// $this->redirect->
die;
}
} else {
$session->write('flash', ['controller' => 'products', 'action' => 'orderCart']);
$this->redirect(['controller' => 'users', 'action' => 'login']);
}
}
开发者ID:thanghexp,项目名称:project,代码行数:31,代码来源:CartsController.php
示例8: display
/**
* Default display method.
*
* @return void
*/
public function display($items = 30)
{
$this->loadModel('Occasions');
$occasionsTable = TableRegistry::get('ArticlesManager.Occasions');
$occasions = $occasionsTable->find('active')->order(['Occasions.date_from' => 'ASC'])->limit($items);
$this->set(compact('occasions'));
}
开发者ID:birdy247,项目名称:ArticlesManager,代码行数:12,代码来源:OccasionCell.php
示例9: expiracao
public function expiracao()
{
$ldap = new LDAP(3);
$vazio = true;
$Usuario = TableRegistry::get("usuario");
$datas = array(5 => (new \DateTime('+ 5 days'))->format('Ymd'), 10 => (new \DateTime('+ 10 days'))->format('Ymd'), 20 => (new \DateTime('+ 20 days'))->format('Ymd'), 30 => (new \DateTime('+ 30 days'))->format('Ymd'));
$html = '';
$usuarios = array();
$chaves = array();
foreach ($datas as $chave => $data) {
$user = $ldap->getUsers("smtDataExpiracao={$data}");
if (count($user) > 1) {
$vazio = false;
$html .= $this->geraHtml($chave, $user);
}
}
if ($vazio) {
$html = "Não há usuários a expirar.";
}
$sus = $Usuario->find()->where(['usuario.idTipoUsuario' => 1]);
$emails = array();
foreach ($sus as $su) {
array_push($emails, $su->login . '@smt.ufrj.br');
}
$email = new Email('gmail');
$email->from(['[email protected]' => 'Controle de Usuarios'])->emailFormat('html')->to($emails)->subject('Notificação de Usuarios a expirar')->send('Usuarios : <br><br>' . $html);
$aviso = new Email('gmail');
$aviso->from(['[email protected]' => 'Controle de Usuarios'])->emailFormat('html')->to('[email protected]')->subject('JOB Realizado')->send('Job Dados Expiração executado com sucesso.');
//return $this->redirect(['action' => 'index']);
$this->set(compact('datas', 'usuarios', 'chaves', 'html'));
}
开发者ID:gbauso,项目名称:asirb,代码行数:31,代码来源:NotificacaoController.php
示例10: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
//Log::drop('default');
//Log::config('default', array('className' => 'DatabaseLog.Database'));
$this->Logs = TableRegistry::get('DatabaseLog.DatabaseLogs');
parent::setUp();
}
开发者ID:dereuromark,项目名称:cakephp-databaselog,代码行数:12,代码来源:DatabaseLogTest.php
示例11: find
/**
* Find data
*
* @param $tableName
* @param array $options
* @return array|\Cake\ORM\Query
*/
public function find($tableName, array $options = [])
{
// -- get table object
$table = TableRegistry::get($tableName);
$this->_tableName = $table->alias();
// -- get query options
$this->_processRequest();
$data = $table->find('all', $options);
// -- record count
$this->_viewVars['recordsTotal'] = $data->count();
// -- filter result
$data->where($this->config('conditions'));
foreach ($this->config('matching') as $association => $where) {
$data->matching($association, function ($q) use($where) {
return $q->where($where);
});
}
$this->_viewVars['recordsFiltered'] = $data->count();
// -- add limit
$data->limit($this->config('length'));
$data->offset($this->config('start'));
// -- sort
$data->order($this->config('order'));
// -- set all view vars to view and serialize array
$this->_setViewVars();
return $data;
}
开发者ID:hareshpatel1990,项目名称:cakephp-datatables,代码行数:34,代码来源:DataTablesComponent.php
示例12: _findUser
/**
* Find a user record using the standard options.
*
* @param string $username The username/identifier.
* @param string $password The password, if not provide password checking is
* skipped and result of find is returned.
* @return bool|array Either false on failure, or an array of user data.
*/
protected function _findUser($username, $password = null)
{
$userModel = $this->_config['userModel'];
list($plugin, $model) = pluginSplit($userModel);
$fields = $this->_config['fields'];
$conditions = [$model . '.' . $fields['username'] => $username];
$columns = [];
foreach ($this->_config['columns'] as $column) {
$columns[] = [$model . '.' . $column => $username];
}
$conditions = ['OR' => $columns];
if (!empty($this->_config['scope'])) {
$conditions = array_merge($conditions, $this->_config['scope']);
}
$table = TableRegistry::get($userModel)->find('all');
if ($this->_config['contain']) {
$table = $table->contain($this->_config['contain']);
}
$result = $table->where($conditions)->hydrate(false)->first();
if (empty($result)) {
return false;
}
if ($password !== null) {
$hasher = $this->passwordHasher();
$hashedPassword = $result[$fields['password']];
if (!$hasher->check($password, $hashedPassword)) {
return false;
}
$this->_needsPasswordRehash = $hasher->needsRehash($hashedPassword);
unset($result[$fields['password']]);
}
return $result;
}
开发者ID:friendsofcake,项目名称:authenticate,代码行数:41,代码来源:MultiColumnAuthenticate.php
示例13: index
public function index()
{
$rulesCategoriesTable = TableRegistry::get('RulesCategories');
$categories = $rulesCategoriesTable->find('all')->contain(['Rules']);
$this->set('categories', $categories);
$this->set('_serialize', ['categories']);
}
开发者ID:MoosemanStudios,项目名称:api.moosecraft.us,代码行数:7,代码来源:RulesController.php
示例14: setUp
public function setUp()
{
parent::setUp();
Configure::write('debug', false);
$this->Articles = TableRegistry::get('Articles');
$this->Authors = TableRegistry::get('Authors');
}
开发者ID:andrej-griniuk,项目名称:cakephp-fractal-transformer-view,代码行数:7,代码来源:FractalTransformerViewTest.php
示例15: afterSave
public function afterSave($event, $entity, $options)
{
$actions = $this->_config['actions'];
$Feed = TableRegistry::get('Social.Feeds');
$user_id = __LOGGEDINUSERID;
$feeds = [];
if ($entity->isNew()) {
// We need to check if the Object has a feed, and if not, create it
$objectFeed = $Feed->find()->where(['Feeds.object_id' => $entity->id, 'Feeds.object' => $this->alias])->first();
if (!$objectFeed) {
$objectFeed = $Feed->newEntity();
$data = ['object_id' => $entity->id, 'object' => $this->alias];
$objectFeed = $Feed->patchEntity($objectFeed, $data);
if ($Feed->save($objectFeed)) {
$this->log("The feed for " . $this->alias . " ID: " . $entity->id . " has been saved!", 'debug');
} else {
$this->log("The feed for " . $this->alias . " ID: " . $entity->id . " could not be saved!", 'debug');
}
}
$feeds[] = $objectFeed->id;
// We need to get the Users feed
$userFeed = $Feed->find()->where(['Feeds.object_id' => $user_id, 'Feeds.object' => 'User'])->first();
// Only add to the Object Feed if it is not the Subject itself
if ($userFeed->id !== $objectFeed->id) {
$feeds[] = $userFeed->id;
}
// If the Object is linked to a Pole, add the Activity to the Pole as well
if (isset($entity->pole_id)) {
$poleFeed = $Feed->find()->where(['Feeds.object_id' => $entity->pole_id, 'Feeds.object' => 'Pole'])->first();
// Only add to the Object Feed if it is not the Subject itself
$feeds[] = $poleFeed->id;
}
// Let's add Activities to all the feeds
$Activity = TableRegistry::get('Social.Activities');
if (array_key_exists('add', $actions)) {
foreach ($actions['add']['fields'] as $field => $options) {
if (isset($entity->{$field})) {
$activity = $Activity->newEntity();
$data = ['object_id' => $entity->id, 'object' => $this->alias, 'subject_id' => $user_id, 'verb' => 'created', 'text' => $options['text'], 'type' => $options['type'], 'pole_id' => isset($entity->pole_id) ? $entity->pole_id : null, 'data' => json_encode(array('field' => $field, 'value' => $entity->{$field})), 'feeds' => ['_ids' => $feeds]];
$activity = $Activity->patchEntity($activity, $data);
if (!$Activity->save($activity)) {
$this->log("The activity could not be saved!", 'debug');
}
}
}
}
// If the Object is not the Subject itself
// Subscribe the User to the Object Feed so that he can be notified
if (!($this->alias == 'User' && $user_id == $entity->id) && count($objectFeed)) {
$Subscription = TableRegistry::get('Social.Subscriptions');
$subscription = $Subscription->newEntity();
$data = ['feed_id' => $objectFeed->id, 'user_id' => $user_id, 'reason' => 'author'];
$subscription = $Subscription->patchEntity($subscription, $data);
if (!$Subscription->save($subscription)) {
$this->log("The subscription could not be saved!", 'debug');
}
}
return true;
}
}
开发者ID:eripoll,项目名称:webiplan,代码行数:60,代码来源:FollowableBehavior.php
示例16: tearDown
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
unset($this->Task);
TableRegistry::clear();
parent::tearDown();
Plugin::unload('ControllerTest');
}
开发者ID:ringiait,项目名称:portal,代码行数:12,代码来源:ControllerTaskTest.php
示例17: index
public function index()
{
$this->viewBuilder()->layout('home');
$productsTable = TableRegistry::get('products');
$products = $productsTable->find('all')->limit(7);
$this->set('products', $products);
}
开发者ID:thanghexp,项目名称:project,代码行数:7,代码来源:HomeController.php
示例18: home
public function home()
{
$search = $this->request->query('q');
$page = $this->request->query('p');
if ($search != null) {
$searchKeywordsEncoded = urlencode($search);
if ($page != null) {
if (!ctype_digit($page)) {
$page = 1;
} else {
if (intval($page) < 1) {
$page = 1;
} else {
if (intval($page) > 10) {
$page = 10;
}
}
}
} else {
$page = 1;
}
$this->set('doNotShowSearchBarInHeader', true);
$searchResult = $this->amazon->search($searchKeywordsEncoded, $page);
$tableOnly = $this->request->query('tableOnly') == "true";
$this->set(compact('searchResult', 'page', 'search', 'tableOnly'));
} else {
$this->set('doNotShowSearchBarInHeader', false);
$productsTable = TableRegistry::get('Products');
$query = $productsTable->find()->contain(['Prices'])->where(['image_link is not' => null])->limit(30);
$products = $query->toArray();
$this->set(compact("products"));
}
}
开发者ID:matdion,项目名称:Product-Tracker,代码行数:33,代码来源:HomesController.php
示例19: processAuthenticate
/**
* Authenticate users based on their JWT. This is inspired by
* the method _findUser in admads JWT plugin
*
* @see https://github.com/ADmad/cakephp-jwt-auth/blob/master/src/Auth/JwtAuthenticate.php
* @param string $token The token identifier.
* @param mixed $extra Unused
* @return array
*/
public function processAuthenticate($token, $extra = null)
{
try {
$token = JWT::decode($token, Security::salt(), Configure::read('Websockets.allowedAlgs'));
} catch (Exception $e) {
if (Configure::read('debug')) {
throw $e;
}
return ["FAILURE"];
}
if ($token->id == 'server') {
return ["SUCCESS", ["authid" => $token->id]];
}
$fields = Configure::read('Websockets.fields');
$table = TableRegistry::get(Configure::read('Websockets.userModel'));
$conditions = [$table->aliasField($fields['id']) => $token->id];
if (!empty(Configure::read('Websockets.scope'))) {
$conditions = array_merge($conditions, Configure::read('Websockets.scope'));
}
$result = $table->find('all')->where($conditions)->first();
if (empty($result)) {
return ["FAILURE"];
}
return ["SUCCESS", ["authid" => $result->id]];
}
开发者ID:gintonicweb,项目名称:websockets,代码行数:34,代码来源:JwtAuthenticationProvider.php
示例20: display
/**
* Displays a view
*
* @return void|\Cake\Network\Response
* @throws \Cake\Network\Exception\NotFoundException When the view file could not
* be found or \Cake\View\Exception\MissingTemplateException in debug mode.
*/
public function display()
{
$articlesTable = TableRegistry::get('Articles');
$articles = $articlesTable->find();
$this->set('articles', $articles);
$this->render('home');
}
开发者ID:wildneybrasil,项目名称:blog-cakephp,代码行数:14,代码来源:PagesController.php
注:本文中的Cake\ORM\TableRegistry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论