本文整理汇总了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);
}