本文整理汇总了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;
}
示例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();
}
示例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');
}
示例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;
}
示例5: read
/**
* 获取用户信息
*/
public function read($uid = null, $field = 'uid')
{
if (!$uid) {
// if ($_SESSION['UID']) {
// $uid = $_SESSION['UID'];
// }
}
return parent::read($uid, 'uid');
}
示例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']));
}
}
示例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);
}
示例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;
}
示例9: getMealPlan
public static function getMealPlan($id)
{
$params = array("id" => $id);
$returnArray = parent::read($params);
return $returnArray[0];
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
}
示例14: readAll
/**
* @return array
*/
public function readAll()
{
return $this->model->read($this->table);
}
示例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':