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


PHP Model::read方法代码示例

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


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

示例1: changeStatus

 public function changeStatus(Model $Model, $status, $id = null, $force = false)
 {
     if ($id === null) {
         $id = $Model->getID();
     }
     if ($id === false) {
         return false;
     }
     $force = true;
     $Model->id = $id;
     if (!$Model->exists()) {
         throw new NotFoundException();
     }
     if ($force !== true) {
         $modelData = $Model->read();
         if ($modelData[$Model->alias]['status'] === $status) {
             CakeLog::write(LOG_WARNING, __d('webshop', 'The status of %1$s with id %2$d is already set to %3$s. Not making a change', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
             return false;
         }
     } else {
         CakeLog::write(LOG_WARNING, __d('webshop', 'Status change of %1$s with id %2$d is being forced to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
     }
     $Model->saveField('status', $status);
     CakeLog::write(LOG_INFO, __d('webshop', 'Changed status of %1$s with id %2$d to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
     $eventData = array();
     $eventData[Inflector::underscore($Model->name)]['id'] = $id;
     $eventData[Inflector::underscore($Model->name)]['status'] = $status;
     $overallEvent = new CakeEvent($Model->name . '.statusChanged', $this, $eventData);
     $specificEvent = new CakeEvent($Model->name . '.statusChangedTo' . Inflector::camelize($status), $this, $eventData);
     CakeEventManager::instance()->dispatch($overallEvent);
     CakeEventManager::instance()->dispatch($specificEvent);
     return true;
 }
开发者ID:cvo-technologies,项目名称:croogo-webshop-plugin,代码行数:33,代码来源:StatusBehavior.php

示例2: createInvoice

 public function createInvoice(Model $Model, $type = 'proforma', $id = null)
 {
     if ($id === null) {
         $id = $Model->getID();
     }
     if ($id === false) {
         return false;
     }
     $Model->id = $id;
     $Model->recursive = 2;
     $order = $Model->read();
     $invoice = array($this->Invoice->alias => array('type' => $type, 'status' => 'open', 'customer_id' => $order[$Model->alias]['customer_id']));
     foreach ($order['OrderProduct'] as $orderProduct) {
         $invoice[$this->Invoice->InvoiceProduct->alias][] = array('amount' => $orderProduct['amount'], 'price' => $orderProduct['price'], 'product_id' => $orderProduct['product_id'], 'tax_revision_id' => $orderProduct['tax_revision_id']);
     }
     foreach ($order['OrderShipment'] as $orderShipment) {
         $invoice[$this->Invoice->InvoiceShippingCost->alias][] = array('amount' => 15, 'shipment_id' => $orderShipment['shipment_id']);
     }
     foreach ($order['OrderPayment'] as $orderPayment) {
         $invoice[$this->Invoice->InvoiceTransactionCost->alias][] = array('amount' => 15, 'payment_id' => $orderPayment['payment_id']);
     }
     $status = $this->Invoice->saveAssociated($invoice, array('deep' => true));
     if (!$status) {
         return false;
     }
     return $this->Invoice->read();
 }
开发者ID:cvo-technologies,项目名称:webshop-invoices,代码行数:27,代码来源:InvoiceTemplateBehavior.php

示例3: testMultipleUploadSaveReadDelete

 public function testMultipleUploadSaveReadDelete()
 {
     // setup
     $this->Model->Behaviors->load('Media.Attachable', array());
     $this->Model->configureAttachment(array('files' => array('baseDir' => $this->attachmentDir, 'multiple' => true, 'removeOnOverwrite' => true)), true);
     $data = array($this->Model->alias => array('title' => 'My Upload', 'files_upload' => array($this->upload1, $this->upload2)));
     // save
     $this->Model->create();
     $result = $this->Model->save($data);
     $this->assertTrue(isset($this->Model->id));
     $this->assertEqual($result[$this->Model->alias]['files_upload'], '');
     $this->assertEqual(preg_match('/Upload_File_1_([0-9a-z]+).txt,Upload_File_2_([0-9a-z]+).txt$/', $result[$this->Model->alias]['files']), 1);
     $this->assertTrue(isset($result['Attachment']['files'][0]['path']));
     $this->assertTrue(file_exists($result['Attachment']['files'][0]['path']));
     $this->assertTrue(isset($result['Attachment']['files'][1]['path']));
     $this->assertTrue(file_exists($result['Attachment']['files'][1]['path']));
     // read
     $modelId = $this->Model->id;
     $this->Model->create();
     $result = $this->Model->read(null, $modelId);
     $this->assertTrue(isset($result[$this->Model->alias]['files']));
     $this->assertTrue(!isset($result[$this->Model->alias]['files_upload']));
     $this->assertEqual(preg_match('/Upload_File_1_([0-9a-z]+).txt,Upload_File_2_([0-9a-z]+).txt$/', $result[$this->Model->alias]['files']), 1);
     $this->assertTrue(isset($result['Attachment']['files'][0]['path']));
     $this->assertTrue(file_exists($result['Attachment']['files'][0]['path']));
     $this->assertTrue(isset($result['Attachment']['files'][1]['path']));
     $this->assertTrue(file_exists($result['Attachment']['files'][1]['path']));
     //delete
     $deleted = $this->Model->delete($this->Model->id);
     $this->assertTrue($deleted, 'Failed to delete Attachment');
     $this->assertTrue(!file_exists($result['Attachment']['files'][0]['path']), 'Attachment not deleted');
     $this->assertTrue(!file_exists($result['Attachment']['files'][1]['path']), 'Attachment not deleted');
 }
开发者ID:fm-labs,项目名称:cakephp-media,代码行数:33,代码来源:AttachableBehaviorTest.php

示例4: beforeDelete

 public function beforeDelete(Model $model, $cascade = true)
 {
     $deletedData = $model->read([$this->getDuplicateKey($model), 'duplicate'], $model->id);
     if (!$deletedData[$model->alias]['duplicate']) {
         $this->setNewOriginal($model, $deletedData[$model->alias][$this->getDuplicateKey($model)]);
     }
     return true;
 }
开发者ID:AmmonMa,项目名称:cake_extras,代码行数:8,代码来源:DuplicateBehavior.php

示例5: read

 /**
  * 获取用户信息
  */
 public function read($uid = null, $field = 'uid')
 {
     if (!$uid) {
         // 			if ($_SESSION['UID']) {
         // 				$uid = $_SESSION['UID'];
         // 			}
     }
     return parent::read($uid, 'uid');
 }
开发者ID:noikiy,项目名称:dophin,代码行数:12,代码来源:User.php

示例6: parentNode

 /**
  * parentNode
  *
  * @param Model $model
  * @return array
  */
 public function parentNode($model)
 {
     if (!$model->id && empty($model->data)) {
         return null;
     }
     $data = $model->data;
     if (empty($model->data)) {
         $data = $model->read();
     }
     if (!isset($data['User']['role_id']) || !$data['User']['role_id']) {
         return null;
     } else {
         return array('Role' => array('id' => $data['User']['role_id']));
     }
 }
开发者ID:beyondkeysystem,项目名称:testone,代码行数:21,代码来源:UserAroBehavior.php

示例7: beforeDelete

 /**
  * Before delete is called before any delete occurs on the attached model, but after the model's
  * beforeDelete is called. Returning false from a beforeDelete will abort the delete.
  *
  * @param Model $model Model using this behavior
  * @param bool $cascade If true records that depend on this record will also be deleted
  * @return mixed False if the operation should abort. Any other result will continue.
  */
 public function beforeDelete(Model $model, $cascade = true)
 {
     if (!empty($model->hasMany['Audit'])) {
         if ($model->id = !empty($model->id) ? $model->id : (!empty($model->data[$model->alias]['id']) ? $model->data[$model->alias]['id'] : '')) {
             $record = $model->read(null);
             $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'] = 'DELETE';
             $this->data[$model->id]['Audit']['old'] = json_encode($record[$model->alias]);
             $this->data[$model->id]['Audit']['new'] = json_encode(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');
         }
     }
     return parent::beforeDelete($model, $cascade);
 }
开发者ID:jsemander,项目名称:cakephp-utilities,代码行数:24,代码来源:AuditableBehavior.php

示例8: read

 /**
  * (non-PHPdoc)
  * @see Model::read()
  */
 public function read($val = null, $field = '', $fetchFields = '*')
 {
     $detail = parent::read($val, $field, $fetchFields);
     if (!$detail) {
         return array();
     }
     if ($this->saveContentType == 'txt') {
         $file = $this->getSaveFile($detail['id']);
         if (is_file($file)) {
             $detail['content'] = file_get_contents($file);
         } else {
             $detail['content'] = '';
         }
     } else {
         $mo = new Model($tbl_content);
         $detail['content'] = $mo->read($detail['id'], 'id', 'content');
     }
     return $detail;
 }
开发者ID:noikiy,项目名称:dophin,代码行数:23,代码来源:Article.php

示例9: getMealPlan

 public static function getMealPlan($id)
 {
     $params = array("id" => $id);
     $returnArray = parent::read($params);
     return $returnArray[0];
 }
开发者ID:ncowan15,项目名称:FoodApp3,代码行数:6,代码来源:mealPlan.php

示例10: read

 /**
  * 读取一条记录
  * @param string|int|float $val
  * @param string $field
  */
 public function read($val = null, $field = '', $fetchFields = '*')
 {
     if ($this->useCache) {
         $this->data = Cache::gets($val, $this->tbl);
         if ($this->data) {
             return $this->data;
         }
     }
     if ($field) {
         $this->data = Db::read($this->tbl, $val, $field, $fetchFields);
     } else {
         $this->data = Db::read($this->tbl, $val, $this->priKey, $fetchFields);
     }
     if ($this->useCache) {
         Cache::setProperties('outputSetKey', true);
         Cache::sets($val, $this->data, $this->tbl, null, null, $this->cacheExpire);
     }
     if ($this->saveContentType == 'txt') {
         $file = $this->getSaveFile($detail['id']);
         if (is_file($file)) {
             $detail['content'] = file_get_contents($file);
         } else {
             $detail['content'] = '';
         }
     } else {
         if ($this->saveContentType == 'db') {
             $mo = new Model($tbl_content);
             $detail['content'] = $mo->read($detail['id'], 'id', 'content');
         }
     }
     return !$this->data ? array() : $this->data;
 }
开发者ID:noikiy,项目名称:dophin,代码行数:37,代码来源:Model.class.php

示例11: __setById

 /**
  *  SetById method. Check is model innitialized.
  *
  *  If $id is defined read record from model with this primary key value
  *
  * @param Model $model
  * @param string $id  - value of model primary key to read
  * @param bool $checkId
  * @return boolean True if model initialized, false if no info in $model->data exists.
  */
 private function __setById(Model $model, $id = null, $checkId = true)
 {
     if (!isset($id)) {
         if ($checkId) {
             return isset($model->data[$model->alias][$model->primaryKey]);
         } else {
             return isset($model->data[$model->alias]);
         }
     } else {
         return $model->read(null, $id);
     }
 }
开发者ID:tetsuo111,项目名称:cakephp,代码行数:22,代码来源:ListBehavior.php

示例12: afterSave

 /**
  * Updates the model's state when a $model->save() call is performed
  * 
  * @param	Model	$model		The model being acted on
  * @param	boolean $created	Whether or not the model was created
  * @param	array	$options	Options passed to save
  * @return	boolean
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     if ($created) {
         $model->read();
         $model->saveField('state', $model->initialState);
     }
     return true;
 }
开发者ID:davidsteinsland,项目名称:cakephp-state-machine,代码行数:16,代码来源:StateMachineBehavior.php

示例13: afterSave

 public function afterSave(Model $model, $created, $options = array())
 {
     # broad check to make sure $model->data has all the fields
     # aggregation doesn't work if the foreignKey isn't in $model->data
     if (array_diff_key($model->schema(), $model->data[$model->alias]) !== array()) {
         $model->read();
     }
     foreach ($this->config[$model->alias] as $aggregate) {
         if (!array_key_exists($aggregate['model'], $model->belongsTo)) {
             continue;
         }
         $foreignKey = $model->belongsTo[$aggregate['model']]['foreignKey'];
         $foreignId = $model->data[$model->alias][$foreignKey];
         $this->__updateCache($model, $aggregate, $foreignKey, $foreignId);
         $oldForeignId = $this->foreignTableIDs[$aggregate['model']];
         if (!$created && $foreignId != $oldForeignId) {
             $this->__updateCache($model, $aggregate, $foreignKey, $oldForeignId);
         }
     }
 }
开发者ID:cwbit,项目名称:cakephp-aggregate-cache,代码行数:20,代码来源:AggregateCacheBehavior.php

示例14: readAll

 /**
  * @return array
  */
 public function readAll()
 {
     return $this->model->read($this->table);
 }
开发者ID:kxopa,项目名称:slim-boilerplate,代码行数:7,代码来源:TableModel.php

示例15: foreach

     foreach ($data as $propname => $value) {
         $propname = ucfirst($propname);
         $setter = "set" . $propname;
         $obj->{$setter}($value);
     }
     $ret = $obj->save();
     $resp = array('msg' => 'sauvegardé', 'data' => $ret);
     header('Content-Type: application/json');
     header('Access-Control-Allow-Origin: *');
     header('Access-Control-Allow-Methods: GET, POST');
     echo json_encode($resp);
     break;
     //read
 //read
 case 'read':
     $obj = Model::read($class, $data->id);
     $obj = json_encode($obj);
     $resp = array('msg' => '', 'data' => $obj);
     header('Content-Type: application/json');
     header('Access-Control-Allow-Origin: *');
     header('Access-Control-Allow-Methods: GET, POST');
     echo json_encode($resp);
     break;
     //update
 //update
 case 'update':
     # code...
     break;
     //delete
 //delete
 case 'delete':
开发者ID:athomix,项目名称:ecommerce,代码行数:31,代码来源:api.php


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