本文整理汇总了PHP中Model类的典型用法代码示例。如果您正苦于以下问题:PHP Model类的具体用法?PHP Model怎么用?PHP Model使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Transforms an object (model) to an integer (int).
*
* @param \Model|null $model
* @return int
*/
public function transform($model)
{
if (empty($model)) {
return 0;
}
return $model->getID();
}
示例2: beforeSave
/**
* beforeSave is called before a model is saved. Returning false from a beforeSave callback
* will abort the save operation.
*
* @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
* @return mixed False if the operation should abort. Any other result will continue.
* @see Model::save()
*/
public function beforeSave(Model $model, $options = array())
{
if (!empty($model->hasMany['Audit'])) {
if ($model->id = !empty($model->id) ? $model->id : (!empty($model->data[$model->alias]['id']) ? $model->data[$model->alias]['id'] : '')) {
$this->data[$model->id]['Audit']['entity'] = (!empty($model->plugin) ? $model->plugin . '.' : '') . $model->name;
$this->data[$model->id]['Audit']['entity_id'] = $model->id;
$this->data[$model->id]['Audit']['event'] = $model->exists() ? 'UPDATE' : 'CREATE';
$this->data[$model->id]['Audit']['new'] = $this->data[$model->id]['Audit']['old'] = array();
$this->data[$model->id]['Audit']['creator_id'] = !empty($model->data['Creator']['id']) ? $model->data['Creator']['id'] : null;
$model->data = Hash::remove($model->data, 'Creator');
if ($this->data[$model->id]['Audit']['event'] == 'CREATE') {
$this->data[$model->id]['Audit']['old'] = json_encode(array());
$this->data[$model->id]['Audit']['new'] = json_encode($model->data[$model->alias]);
} else {
if ($this->data[$model->id]['Audit']['event'] == 'UPDATE') {
$old = $model->find('first', array('conditions' => array($model->alias . '.id' => $model->id), 'recursive' => -1));
foreach ($model->data[$model->alias] as $field => $value) {
if ($field == 'updated') {
continue;
}
if ($model->hasField($field) && $old[$model->alias][$field] != $value) {
$this->data[$model->id]['Audit']['old'][$field] = $old[$model->alias][$field];
$this->data[$model->id]['Audit']['new'][$field] = $value;
}
}
if (!empty($this->data[$model->id]['Audit']['old']) && !empty($this->data[$model->id]['Audit']['new'])) {
$this->data[$model->id]['Audit']['old'] = json_encode($this->data[$model->id]['Audit']['old']);
$this->data[$model->id]['Audit']['new'] = json_encode($this->data[$model->id]['Audit']['new']);
}
}
}
}
}
return parent::beforeSave($model, $options);
}
示例3: remover
public static function remover(Model $uf)
{
if ($uf->get("id")) {
$sql = "delete from uf where id = :id";
}
return self::exec($sql, $uf);
}
示例4: create_topic
function create_topic($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die('', 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data)) {
Util::output_errors_and_die('', 400);
}
$model = new Model();
if (!isset($input_data['name'])) {
$input_data['name'] = '';
}
$topic_id = $model->create_topic($input_data['name']);
if ($topic_id) {
http_response_code(201);
header('Content-Type: text/plain');
echo '/topics/' . $topic_id;
die;
} else {
Util::output_errors_and_die('', 400);
}
} catch (ConflictException $e) {
Util::output_errors_and_die($e->getMessage(), 409);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例5: setup
/**
* Adjust configs like: $Model->Behaviors-attach('Tools.DecimalInput', array('fields'=>array('xyz')))
* leave fields empty to auto-detect all float inputs
*
* @return void
*/
public function setup(Model $Model, $config = array())
{
$this->settings[$Model->alias] = $this->_defaultConfig;
if (!empty($config['strict'])) {
$this->settings[$Model->alias]['transform']['.'] = '#';
}
if ($this->settings[$Model->alias]['localeconv'] || !empty($config['localeconv'])) {
// use locale settings
$conv = localeconv();
$loc = array('decimals' => $conv['decimal_point'], 'thousands' => $conv['thousands_sep']);
} elseif ($configure = Configure::read('Localization')) {
// Use configure settings
$loc = (array) $configure;
}
if (!empty($loc)) {
$this->settings[$Model->alias]['transform'] = array($loc['thousands'] => $this->settings[$Model->alias]['transform']['.'], $loc['decimals'] => $this->settings[$Model->alias]['transform'][',']);
}
$this->settings[$Model->alias] = $config + $this->settings[$Model->alias];
$numberFields = array();
$schema = $Model->schema();
foreach ($schema as $key => $values) {
if (isset($values['type']) && !in_array($key, $this->settings[$Model->alias]['fields']) && in_array($values['type'], $this->settings[$Model->alias]['observedTypes'])) {
array_push($numberFields, $key);
}
}
$this->settings[$Model->alias]['fields'] = array_merge($this->settings[$Model->alias]['fields'], $numberFields);
}
示例6: bindTagAssociations
/**
* Bind tag assocations
*
* @param Model $model Model instance that behavior is attached to
* @return void
*/
public function bindTagAssociations(Model $model)
{
extract($this->settings[$model->alias]);
list($plugin, $withClass) = pluginSplit($withModel, true);
$model->bindModel(array('hasAndBelongsToMany' => array($tagAlias => array('className' => $tagClass, 'foreignKey' => $foreignKey, 'associationForeignKey' => $associationForeignKey, 'unique' => true, 'conditions' => array($withClass . '.model' => $model->name), 'fields' => '', 'dependent' => true, 'with' => $withModel))), $resetBinding);
$model->{$tagAlias}->bindModel(array('hasMany' => array($taggedAlias => array('className' => $taggedClass))), $resetBinding);
}
示例7: _parseJoins
/**
* Recursively parses joins
*
* @param Model $Model
* @param array $joins
* @return array
*/
protected function _parseJoins(Model $Model, $joins, $defaults = array())
{
$ds = $Model->getDataSource();
$defaults = array_merge($this->_defaults, $defaults);
if (isset($joins['defaults'])) {
$defaults = array_merge($defaults, $joins['defaults']);
unset($joins['defaults']);
}
foreach ((array) $joins as $association => $options) {
if (is_string($options)) {
if (is_numeric($association)) {
$association = $options;
$options = array();
} else {
$options = (array) $options;
}
}
$AssociatedModel = $this->_associatedModel($Model, $association);
$deeperAssociations = array_diff_key($options, $defaults);
$options = array_merge($defaults, $options);
$this->_join($Model, $association, $options['conditions'], $options['type']);
$fields = false;
if ($options['fields'] === true) {
$fields = null;
} elseif (!empty($options['fields'])) {
$fields = $options['fields'];
}
if ($fields !== false) {
$this->_query['fields'] = array_merge($this->_query['fields'], $ds->fields($AssociatedModel, null, $fields));
}
if (!empty($deeperAssociations)) {
$this->_parseJoins($AssociatedModel, $deeperAssociations, $defaults);
}
}
}
示例8: getMsgList
function getMsgList($parm = array())
{
$M = new Model('member_msg');
$pre = C('DB_PREFIX');
$field = true;
$orderby = " id DESC";
if ($parm['pagesize']) {
//分页处理
import("ORG.Util.Page");
$count = $M->where($parm['map'])->count('id');
$p = new \Org\Util\Page($count, $parm['pagesize']);
$page = $p->show();
$Lsql = "{$p->firstRow},{$p->listRows}";
//分页处理
} else {
$page = "";
$Lsql = "{$parm['limit']}";
}
$data = M('member_msg')->field(true)->where($parm['map'])->order($orderby)->limit($Lsql)->select();
$symbol = C('MONEY_SYMBOL');
$suffix = C("URL_HTML_SUFFIX");
foreach ($data as $key => $v) {
}
$row = array();
$row['list'] = $data;
$row['page'] = $page;
$row['count'] = $count;
return $row;
}
示例9: addToBasket
public function addToBasket(Model $Model, $id, array $options = array())
{
$options = Hash::merge(array('basket' => $Model->ShoppingBasketItem->ShoppingBasket->currentBasketId(), 'amount' => 1, 'configuration' => array(), 'non_overridable' => array()), array_filter($options));
$configurationGroupIds = $Model->ItemConfigurationGroup->find('list', array('fields' => array('ConfigurationGroup.id'), 'conditions' => array('ItemConfigurationGroup.foreign_key' => $id, 'ItemConfigurationGroup.model' => $Model->name), 'contain' => array('ConfigurationGroup')));
$valueData = $Model->ShoppingBasketItem->ConfigurationValue->generateValueData($Model->ShoppingBasketItem->name, $configurationGroupIds, $options['configuration'], $options['non_overridable']);
$stackable = $Model->field('stackable', array('id' => $id));
if ($stackable) {
$shoppingBasketItemId = $Model->ShoppingBasketItem->field('id', array('ShoppingBasketItem.shopping_basket_id' => $options['basket'], 'ShoppingBasketItem.product_id' => $id));
if (!$shoppingBasketItemId) {
$Model->ShoppingBasketItem->create();
$data = $Model->ShoppingBasketItem->saveAssociated(array('ShoppingBasketItem' => array('shopping_basket_id' => $options['basket'], 'product_id' => $id, 'amount' => $options['amount']), 'ConfigurationValue' => $valueData));
return $data;
}
$Model->ShoppingBasketItem->id = $shoppingBasketItemId;
$amount = $Model->ShoppingBasketItem->field('amount');
return $Model->ShoppingBasketItem->saveField('amount', $amount + $options['amount']);
}
for ($number = 1; $number <= $options['amount']; $number++) {
$Model->ShoppingBasketItem->create();
$data = $Model->ShoppingBasketItem->saveAssociated(array('ShoppingBasketItem' => array('shopping_basket_id' => $options['basket'], 'product_id' => $id, 'amount' => 1), 'ConfigurationValue' => $valueData));
if (!$data) {
return false;
}
}
return true;
}
示例10: beforeValidate
/**
* beforeValidate is called before a model is validated, you can use this callback to
* add behavior validation rules into a models validate array. Returning false
* will allow you to make the validation fail.
*
* @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
* @return mixed False or null will abort the operation. Any other result will continue.
* @see Model::save()
*/
public function beforeValidate(Model $model, $options = array())
{
$model->loadModels(array('CircularNoticeContent' => 'CircularNotices.CircularNoticeContent', 'CircularNoticeTargetUser' => 'CircularNotices.CircularNoticeTargetUser', 'User' => 'Users.User'));
if (!$model->data['CircularNoticeContent']['is_room_target']) {
// 回覧先ユーザのバリデーション処理
if (!isset($model->data['CircularNoticeTargetUser'])) {
$model->data['CircularNoticeTargetUser'] = array();
}
$model->CircularNoticeTargetUser->set($model->data['CircularNoticeTargetUser']);
// ユーザ選択チェック
$targetUsers = Hash::extract($model->data['CircularNoticeTargetUser'], '{n}.user_id');
if (!$model->CircularNoticeTargetUser->isUserSelected($targetUsers)) {
$model->CircularNoticeTargetUser->validationErrors['user_id'] = sprintf(__d('circular_notices', 'Select user'));
$model->validationErrors = Hash::merge($model->validationErrors, $model->CircularNoticeTargetUser->validationErrors);
return false;
}
if (!$model->CircularNoticeTargetUser->validates()) {
$model->validationErrors = Hash::merge($model->validationErrors, $model->CircularNoticeTargetUser->validationErrors);
return false;
}
if (!$model->User->existsUser($targetUsers)) {
$model->CircularNoticeTargetUser->validationErrors['user_id'][] = sprintf(__d('net_commons', 'Failed on validation errors. Please check the input data.'));
$model->validationErrors = Hash::merge($model->validationErrors, $model->CircularNoticeTargetUser->validationErrors);
return false;
}
}
return true;
}
示例11: import
function import($sFile)
{
if (!$this->bSpycReady) {
return self::SPYC_CLASS_NOT_FOUND;
}
if (!file_exists($sFile)) {
return self::YAML_FILE_NOT_FOUND;
}
$this->aTables = SPYC::YAMLload(file_get_contents($sFile));
if (!is_array($this->aTables)) {
return self::YAML_FILE_IS_INVALID;
}
uses('model' . DS . 'model');
$oDB = $this->oDb;
$aAllowedTables = $oDB->listSources();
foreach ($this->aTables as $table => $records) {
if (!in_array($oDB->config['prefix'] . $table, $aAllowedTables)) {
return self::TABLE_NOT_FOUND;
}
$temp_model = new Model(false, $table);
foreach ($records as $record_num => $record_value) {
if (!isset($record_value['id'])) {
$record_value['id'] = $record_num;
}
if (!$temp_model->save($record_value)) {
return array('error' => array('table' => $table, 'record' => $record_value));
}
}
}
return true;
}
示例12: get_user_price_list
public function get_user_price_list($user_id)
{
$model = new Model();
$condition['user_id'] = $user_id;
$list = $model->table('ldh_price_user')->field('ldh_price.code,ldh_price.password,ldh_price_user.price_id')->join('ldh_price ON ldh_price_user.price_id = ldh_price.price_id')->where($condition)->select();
return $list;
}
示例13: __construct
public function __construct($util, $get = null)
{
parent::__construct($util);
$this->model();
$this->setViewMenu();
if (isset($get["vers"])) {
$vers = $get["vers"];
} else {
$vers = 1;
}
if (isset($get["depuis"])) {
$depuis = $get["depuis"];
} else {
$depuis = 1;
}
$model = new Model();
if (isset($get["enregistrer"])) {
//on a cliqué un bouton enregistrer
if (isset($get["li"])) {
//il y a des situs (inutile ici...)
$model->validSitu($get["chk"], $this->util->getId(), $get["li"]);
}
}
$data["lessitus"] = $model->getSitus($util->getId(), $util->getNumGroupe(), $vers);
$data["auth"] = $this->util->estAuthent();
$data["vers"] = $vers;
$data["type"] = "V";
//validations
$this->view->init('dessitus.php', $data);
$this->setViewBas();
$model->close();
}
示例14: __construct
function __construct()
{
$model = new Model();
$this->connection = $model->get_connection();
//$this->connection = new mysqli('sql4.freemysqlhosting.net', 'sql497000', 'bGNjUbh2SS', 'sql497000');
$this->check();
}
示例15: many_to_many
public function many_to_many(Model $reference)
{
$columns1 = parent::findConstraitn('PrimaryKey')->getColumns();
$columns2 = $reference->findConstraitn('PrimaryKey')->getColumns();
$mtm = ManyToMany::getInstance(parent::persistence(), $reference->persistence(), $columns1, $columns2);
$this->weaks_entitys[get_class($mtm)] = $mtm;
}