本文整理匯總了PHP中ArrayUtil::coerceToArray方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArrayUtil::coerceToArray方法的具體用法?PHP ArrayUtil::coerceToArray怎麽用?PHP ArrayUtil::coerceToArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ArrayUtil
的用法示例。
在下文中一共展示了ArrayUtil::coerceToArray方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: afterSave
public function afterSave($evt)
{
// file attribute value is expected to be either an id of old associated media or
// an instance of CUploadedFile. Can also be an array containing either.
$fileAttribute = $this->fileAttribute;
$transaction = Yii::app()->db->beginTransaction();
try {
$files = ArrayUtil::coerceToArray($this->owner->{$fileAttribute});
// remove old associated media with ids not found in file attribute
$resubmittedMediaIds = array();
foreach ($files as $file) {
if (!$file instanceof CUploadedFile && is_numeric($file)) {
$resubmittedMediaIds[] = (int) $file;
}
}
$associatedMedia = Media::model()->findAllByAttributes(array('associationType' => $this->associationType, 'associationId' => $this->getAssociationId()));
foreach ($associatedMedia as $media) {
if (!in_array((int) $media->id, $resubmittedMediaIds, true)) {
$media->delete();
}
}
// save uploaded files as associated media
foreach ($files as $file) {
$this->saveAssociatedMedia($file);
}
$transaction->commit();
} catch (CException $e) {
$transaction->rollback();
}
}
示例2: coerceToArray
/**
* @deprecated
*/
public static function coerceToArray(&$arr)
{
$arr = ArrayUtil::coerceToArray($arr);
}