本文整理汇总了PHP中ActiveRecord::getInstanceById方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::getInstanceById方法的具体用法?PHP ActiveRecord::getInstanceById怎么用?PHP ActiveRecord::getInstanceById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::getInstanceById方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteById
public static function deleteById($id)
{
self::deleteCache();
// make sure the language record exists
$inst = ActiveRecord::getInstanceById('Language', $id, true);
// make sure it's not the default currency
if (true != $inst->isDefault->get()) {
ActiveRecord::deleteByID('Language', $id);
return true;
} else {
return false;
}
}
示例2: save
public function save()
{
ActiveRecord::beginTransaction();
$image = null;
try {
$image = ActiveRecord::getInstanceById($this->getModelClass(), $this->request->get('imageId'), true);
$multilingualFields = array("title");
$image->setValueArrayByLang($multilingualFields, $this->application->getDefaultLanguageCode(), $this->application->getLanguageArray(true), $this->request);
$image->save();
if ($_FILES['image']['tmp_name']) {
$resizer = new ImageManipulator($_FILES['image']['tmp_name']);
if (!$resizer->isValidImage()) {
throw new InvalidImageException();
}
if (!$image->resizeImage($resizer)) {
throw new ImageResizeException();
}
}
} catch (InvalidImageException $exc) {
$error = $this->translate('_err_not_image');
} catch (ImageResizeException $exc) {
$error = $this->translate('_err_resize');
} catch (Exception $exc) {
$error = $this->translate('_err_not_found ' . get_class($exc));
}
$response = new ActionResponse();
if (isset($error)) {
ActiveRecord::rollback();
$result = array('error' => $error);
} else {
ActiveRecord::commit();
$result = $image->toArray();
}
$this->setLayout('iframeJs');
$response->set('ownerId', $this->request->get('ownerId'));
$response->set('imageId', $this->request->get('imageId'));
$response->set('result', @json_encode($result));
return $response;
}
示例3: setEnabled
/**
* Sets if currency is enabled
* @role status
* @return ActionResponse
*/
public function setEnabled()
{
$id = $this->request->get('id');
$curr = ActiveRecord::getInstanceById('Currency', $id, true);
$curr->isEnabled->set((int) (bool) $this->request->get("status"));
$curr->save();
return new JSONResponse(array('currency' => $curr->toArray()), 'success');
}
示例4: restoreInstance
public function restoreInstance()
{
$instance = ActiveRecord::getInstanceById($this->instanceClassName, $this->instanceId);
return $instance;
}