本文整理汇总了PHP中ORM::for_table方法的典型用法代码示例。如果您正苦于以下问题:PHP ORM::for_table方法的具体用法?PHP ORM::for_table怎么用?PHP ORM::for_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ORM
的用法示例。
在下文中一共展示了ORM::for_table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public function update($table, $id, $ignore_keys = null)
{
if ($_POST) {
$params = $_POST;
$this->crud->save($table, $params, $id);
$this->view = new Create('done');
} else {
$fields = \ORM::for_table($table)->raw_query('DESCRIBE ' . $table)->find_array();
$row = $this->crud->read($table, $id);
if ($ignore_keys) {
foreach ($row as $key => $value) {
if (in_array($key, $ignore_keys)) {
unset($row[$key]);
}
}
foreach ($fields as $key => $field) {
if (in_array($field['Field'], $ignore_keys)) {
unset($fields[$key]);
}
}
}
$data['fields'] = $fields;
$data['row'] = $row;
$this->view = new Update('update', $data);
}
}
示例2: find
public function find($tag, $key = "tags")
{
// search pages table with pages that has a certain tag
$r = \ORM::for_table('cms_page')->distinct()->select('cms_page.*')->join('cms_page_meta', array('cms_page.id', '=', 'cms_page_meta.page_id'))->join('cms_page_meta_translation', array('cms_page_meta.id', '=', 'cms_page_meta_translation.meta_id'))->where_equal('cms_page_meta.key', $key)->where_raw("FIND_IN_SET({$tag}, cms_page_meta_translation.value)")->find_many();
print_r($r);
print_r(\ORM::get_last_query());
}
示例3: run
/**
* Выполним действие
*
* @param string $user_email Адрес электронной почты
*
* @return array
*
* @version 13.09.2016
* @author Дмитрий Щербаков <atomcms@ya.ru>
*/
public function run($user_email)
{
$result = ['error' => true, 'message' => 'Неизвестная ошибка.'];
// Сформируем запрос на смену пароля
$result = $this->di->auth->requestReset($user_email, false);
if ($result['error'] === false) {
// Найдем ИД пользователя
$user_info = \ORM::for_table('users')->select('id')->where_equal('email', $user_email)->find_one();
if (is_object($user_info)) {
// Найдем в базе ключ для отправки собственного письма
$request_info = \ORM::for_table($this->di->auth->config->table_requests)->select('rkey')->where(['uid' => $user_info->id, 'type' => 'reset'])->find_one();
if (is_object($request_info)) {
// Отправим сообщение на почту
$send_result = $this->di->mail->send($user_email, 'Запрос на изменение пароля в "' . $this->di->auth->config->site_name . '"', 'USER_LOST', ['[[SITE_NAME]]' => $this->di->auth->config->site_name, '[[SITE_URL]]' => $this->di->auth->config->site_url, '[[USER_EMAIL]]' => $user_email, '[[KEY]]' => $request_info->rkey]);
if ($send_result) {
return ['error' => false, 'message' => 'Запрос успешно отправлен на электронную почту "' . $user_email . '".'];
} else {
$result['message'] = 'Произошла ошибка. Пожалуйста, обратитесь к разработчику.';
}
} else {
$this->di->log->warning('Для запроса на восстановление пароля не найден ключ восстановления: "' . $user_email . '" (#' . $user_info->id . ', type=reset).');
$result['message'] = 'Произошла ошибка. Пожалуйста, обратитесь к разработчику.';
}
} else {
$this->di->log->warning('Для запроса на восстановление пароля не найден пользователь: "' . $user_email . '".');
$result['message'] = 'Произошла ошибка. Пожалуйста, обратитесь к разработчику.';
}
} else {
$result['message'] = $result['message'];
}
return $result;
}
示例4: start
function start()
{
if (!empty($_POST)) {
if (!isset($_POST['id'])) {
createUser($_POST);
} else {
editUser($_POST);
}
require '../views/list.php';
return;
}
if (!isset($_GET['id']) && !isset($_GET['page'])) {
$people = getPeople();
require '../views/list.php';
return;
}
if (isset($_GET['page']) && $_GET['page'] === 'add') {
require '../views/add.php';
return;
}
if (isset($_GET['page']) && $_GET['page'] === 'edit') {
if (!isset($_GET['id'])) {
die('veuillez spécifier un id d\'utilisateur');
}
$id = $_GET['id'];
$editable = ORM::for_table('users')->find_one($id);
require '../views/edit.php';
return;
}
$user = getUser();
require '../views/show.php';
}
示例5: idiorm
private function idiorm($path)
{
if (!mapi_include_abs_path($path, 'lib')) {
return null;
}
if (!isset(MSettings::$db_host) || !strlen(MSettings::$db_host) > 0) {
return false;
}
if (!isset(MSettings::$db) || !strlen(MSettings::$db) > 0) {
return false;
}
if (!isset(MSettings::$db_user) || !strlen(MSettings::$db_user) > 0) {
return false;
}
if (!isset(MSettings::$db_pass) || !strlen(MSettings::$db_pass) > 0) {
return false;
}
try {
ORM::configure('mysql:host=' . MSettings::$db_host . ';dbname=' . MSettings::$db);
ORM::configure('username', MSettings::$db_user);
ORM::configure('password', MSettings::$db_pass);
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
$test = ORM::for_table('preferences')->create();
if ($test) {
return true;
} else {
return false;
}
} catch (PDOException $e) {
return false;
}
}
示例6: require_login
function require_login(&$app, $redirect = true)
{
$params = $app->request()->params();
if (array_key_exists('token', $params)) {
try {
$data = JWT::decode($params['token'], Config::$jwtSecret);
$_SESSION['user_id'] = $data->user_id;
$_SESSION['me'] = $data->me;
} catch (DomainException $e) {
if ($redirect) {
header('X-Error: DomainException');
$app->redirect('/', 301);
} else {
return false;
}
} catch (UnexpectedValueException $e) {
if ($redirect) {
header('X-Error: UnexpectedValueException');
$app->redirect('/', 301);
} else {
return false;
}
}
}
if (!array_key_exists('user_id', $_SESSION)) {
if ($redirect) {
$app->redirect('/');
}
return false;
} else {
return ORM::for_table('users')->find_one($_SESSION['user_id']);
}
}
示例7: to_url_alias
private function to_url_alias()
{
$existing = $this->get_url_alias();
if (!$existing) {
\ORM::for_table($this->table('url_alias'))->create(array('query' => join('=', array($this->id_field, $this->id())), 'keyword' => strtolower($this->name)))->save();
}
}
示例8: dbInsert
function dbInsert($row, $user)
{
ORM::configure(array('connection_string' => 'mysql:host=localhost;dbname=qiita', 'username' => 'xxxx', 'password' => 'xxxx', 'driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), 'error_mode', PDO::ERRMODE_WARNING, 'logging', true));
//記事登録
$items = ORM::for_table('items')->where_equal('item_id', $row['item_id'])->find_one();
if (!$items) {
//未登録の記事は登録
$items = ORM::for_table('items')->create();
$items->set($row);
$items->save();
}
//ユーザ情報登録
$users = ORM::for_table('users')->where_equal('user_id', $user['user_id'])->find_one();
print_r($user);
echo $user['user_id'];
if (!$users) {
//未登録のユーザは登録
$users = ORM::for_table('users')->create();
$users->set($user);
echo " 登録<br>";
} else {
//登録済のユーザは更新
$users->set($user);
echo " 更新<br>";
}
$users->save();
}
示例9: increment
public function increment($id)
{
$counter = ORM::for_table('counters')->find_one($id);
$counter->count = $counter->count + 1;
$counter->save();
return $counter->count;
}
示例10: query
public function query()
{
if (!isset($this->table)) {
throw new \Exception("Database Error", "Database queries require a table to be set");
}
return Query::for_table($this->table);
}
示例11: getOrm
function getOrm()
{
if (!$this->orm) {
$this->orm = \ORM::for_table('');
}
return $this->orm;
}
示例12: for_table
public function for_table($tableName)
{
if (!isset($this->tables[$tableName])) {
$this->tables[$tableName] = \ORM::for_table($tableName, $this->connectionName);
}
return $this->tables[$tableName];
}
示例13: get_many
public function get_many($day = null)
{
$items = \ORM::for_table($this->tableName);
// Search
$query = $this->bcms->request->get('query');
$query = filter_var($query, FILTER_SANITIZE_STRING);
if ($query) {
$items = $items->where_like('title', '%' . $query . '%');
$this->bcms->view->appendData(array('query' => $query));
}
// Where
$where = $this->bcms->request->get('where');
$where = filter_var($where, FILTER_SANITIZE_STRING);
if ($where) {
$items = $items->where_like('where', $where . '%');
$this->bcms->view->appendData(array('where' => $where));
}
// day
if (!$day) {
$day = $this->bcms->request->get('day');
$day = filter_var($day, FILTER_SANITIZE_STRING);
}
if ($day) {
$items = $items->where_gte('date_created', $day);
$nextDayTime = strtotime($day) + 60 * 60 * 24;
$items = $items->where_lt('date_created', date('Y-m-d', $nextDayTime));
$this->bcms->view->appendData(array('day' => $day));
}
$items = $items->order_by_desc('date_created');
$items = $items->find_array();
if (!$items) {
return false;
}
return $items;
}
示例14: find_type
private static function find_type($id)
{
$record = ORM::for_table('contents')->select('type')->find_one(intval($id));
if (!$record) {
return null;
}
return ucfirst($record->type);
}
示例15: loadBySuburb
public function loadBySuburb($suburb)
{
$location = \ORM::for_table('location')->where('suburb', $suburb)->find_one();
$this->_suburb = trim(strpos($suburb, " (") !== false ? substr($suburb, 0, strpos($suburb, " (")) : $suburb);
$this->_district = $location["district"];
$this->_region = $location["region"];
$this->_state = $location["state"];
}