本文整理汇总了PHP中CMap::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::toArray方法的具体用法?PHP CMap::toArray怎么用?PHP CMap::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMap
的用法示例。
在下文中一共展示了CMap::toArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFlashMessage
/**
* @param $message
// пример использования в контроллере:
// $err = array('test1','test2'); // складываем ошибки в массив // можно доделать с использовать _addError как в контроллере orders/cart если запрос через ajax
// Yii::app()->user->setFlash('messages_red', $err);
// $this->addFlashMessage($model->getErrors(),'red'); // до кучи берем ошибки модели
// Если была/были впереди ошибка/ошибки, показываем все
*/
public function addFlashMessage($message, $style = 'success')
{
$currentMessages = Yii::app()->user->getFlash('error');
if (!is_array($currentMessages)) {
$currentMessages = array($currentMessages);
}
$map = new CMap($currentMessages);
if (is_array($message)) {
foreach ($message as $mes) {
if (is_array($mes)) {
$map->mergeWith($mes);
} else {
$map->mergeWith(array($mes));
}
}
} else {
$map->mergeWith(array($message));
}
$messages = $map->toArray();
Yii::app()->user->setFlash($style, $messages);
}
示例2: testToArray
public function testToArray()
{
$map = new CMap(array('key' => 'value'));
$this->assertEquals(array('key' => 'value'), $map->toArray());
}
示例3: actionGetGroceryRate
public function actionGetGroceryRate()
{
$inquiry = new InquiryForm('api-rate-grocery');
$req = Yii::app()->request;
$inquiryMap = new CMap();
$inquiryMap->add('receiver_postal', $req->getQuery('receiver_postal'));
$inquiryMap->add('service_code', $req->getQuery('service_code'));
$inquiry->setAttributes($inquiryMap->toArray());
if (!$inquiry->validate()) {
echo CJSON::encode($this->statusError($inquiry->getErrors()));
Yii::app()->end();
}
$service_code = ProductService::model()->findByAttributes(array('code' => strtoupper($inquiry->service_code)));
if (!$service_code instanceof ProductService) {
echo CJSON::encode($this->statusError('No Service Available'));
Yii::app()->end();
} else {
if ($service_code->code != 'LSX' && $service_code->code != 'HRX') {
echo CJSON::encode($this->statusError('This service is not available'));
Yii::app()->end();
}
}
$routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
if ($routing instanceof IntraCityRouting) {
$area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
if (!$area) {
echo CJSON::encode($this->statusError('No Available Service'));
Yii::app()->end();
}
$rates = RateCity::getCityRate(ProductService::ProductCityCourier, $routing->code, 5);
$rate = array();
foreach ($rates as $key) {
if ($key['service_code'] == $inquiry->service_code) {
$rate = $key;
}
}
$product = 'City Courier';
echo CJSON::encode($this->statusSuccess(array('service_type' => $product, 'rate' => $rate)));
Yii::app()->end();
} else {
$result = array('status' => 'success', 'result' => $data);
}
echo CJSON::encode($result);
Yii::app()->end();
}
示例4: processAttributes
/**
* Save model attributes
* @param ShopProduct $model
* @return boolean
*/
protected function processAttributes(ShopProduct $model)
{
$attributes = new CMap(Yii::app()->request->getPost('ShopAttribute', array()));
if (empty($attributes)) {
return false;
}
$deleteModel = ShopProduct::model()->findByPk($model->id);
$deleteModel->deleteEavAttributes(array(), true);
// Delete empty values
foreach ($attributes as $key => $val) {
if (is_string($val) && $val === '') {
$attributes->remove($key);
}
}
return $model->setEavAttributes($attributes->toArray(), true);
}
示例5: processAttributes
/**
* Save model attributes
* @param Products $model
* @return boolean
*/
protected function processAttributes($attributes)
{
$attributes = new CMap($attributes);
if(empty($attributes))
return false;
$this->deleteEavAttributes(array(), true);
// Delete empty values
foreach($attributes as $key=>$val)
{
if(is_string($val) && $val === '')
$attributes->remove($key);
}
return $this->setEavAttributes($attributes->toArray(), true);
}