本文整理汇总了PHP中yii\helpers\ArrayHelper::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::toArray方法的具体用法?PHP ArrayHelper::toArray怎么用?PHP ArrayHelper::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionPostDispatch
public function actionPostDispatch()
{
$dispatch_model_1 = array();
$dispatch_model_2 = array();
$dispatch_id = Yii::$app->request->post('document_number');
if (isset($dispatch_id)) {
//Yii::app()->session['dispatch_id'] = $dispatch_id;
$full_dispatch_id = '00' . $dispatch_id;
$dismodel = new DispatchModel();
$dispatch_model_1 = $dismodel->getDispatchList($full_dispatch_id);
$dispatch_model_3 = $dismodel->getPickedBy($full_dispatch_id);
$sap_dispatch = $this->getSapDispatch($full_dispatch_id);
$ditems = $dismodel->getDispatchItems($full_dispatch_id);
$dispatch_model_2 = array();
foreach ($ditems as $key => $item) {
$mm = Yii::$app->modelFinder->getMaterialBy(null, ['like', 'item_code', $item->MATNR]);
if (empty($mm)) {
$speclist['0']['barcode'] = "";
$speclist['0']['upc_1'] = "";
$speclist['0']['upc_2'] = "";
$speclist = array(array('barcode' => '', 'upc_1' => '', 'upc_2' => ''));
} else {
$speclist = ArrayHelper::toArray($mm);
}
$result = array('MATNR' => $item->MATNR, 'ARKTX' => $item->ARKTX, 'CHARG' => $item->CHARG, 'UMVKZ' => $item->UMVKZ, 'BRGEW' => $item->BRGEW, 'VRKME' => $item->VRKME, 'LFIMG' => $item->LFIMG, 'VFDAT' => $item->VFDAT, 'MEINS' => $item->MEINS, 'VOLUM' => $item->VOLUM, 'UMVKN' => $item->UMVKN, 'BARCODE' => $speclist['0']['barcode'], 'UPC_1' => $speclist['0']['upc_1'], 'UPC_2' => $speclist['0']['upc_2']);
$dispatch_model_2[] = (object) $result;
}
return $this->render('dispatch-print-form', ['dispatch_model_1' => $dispatch_model_1, 'dispatch_model_2' => $dispatch_model_2, 'dispatch_model_3' => $dispatch_model_3, 'full_dispatch_id' => $full_dispatch_id, 'sap_dispatch' => $sap_dispatch]);
} else {
return $this->render('index');
}
}
示例2: __ModelTabsConstruct
public function __ModelTabsConstruct($rowParams = [], $value = "", $item = [])
{
$model_tabs = new \app\modelsActiveRecords\Tabs();
$getTabs = $model_tabs->GetItems($value);
$tabs = ArrayHelper::toArray($getTabs);
$params = yii::$app->request->bodyParams;
if (!empty($params["tabs"])) {
$model_tabs->Add($value, $params["tabs"]);
}
$tag = Html::beginTag('table', ['style' => 'width:100%']);
$tag .= Html::a('Добавить поле', 'javascript:void(0)', ['onclick' => 'addTabRow(this)']);
$tag .= Html::beginTag('tr');
$tag .= Html::tag('th', 'Имя вкладки');
$tag .= Html::tag('th', 'Название вкладки');
$tag .= Html::tag('th', 'Класс');
$tag .= Html::tag('th', 'Индекс сортировки');
$tag .= Html::tag('th', 'Действие');
$tag .= Html::endTag('tr');
if (!empty($tabs)) {
foreach ($tabs as $index => $value) {
$tag .= Html::beginTag('tr');
$tag .= Html::tag('td', Html::textInput("tabs[{$index}][name]", $value["name"]));
$tag .= Html::tag('td', Html::textInput("tabs[{$index}][title]", $value["title"]));
$tag .= Html::tag('td', Html::textInput("tabs[{$index}][class]", $value["class"]));
$tag .= Html::tag('td', Html::textInput("tabs[{$index}][index]", $value["index"], ["type" => "number"]));
$tag .= Html::tag('td', Html::a('Удалить', 'javascript:void(0)', ['onclick' => 'removeRow(this)']));
$tag .= Html::endTag('tr');
}
}
$tag .= Html::endTag('table');
return $tag;
}
示例3: run
/**
*
* @param string $config
* @return type
*/
public function run($config = [])
{
$id = $this->getId();
CalendarAsset::register($this->getView());
if (!empty($config['id'])) {
$id = $config['id'];
}
if (!empty($config['source'])) {
$this->source = $config['source'];
}
if (!isset($config['class'])) {
$config['class'] = 'calendar-holder';
}
$content = Html::tag('div', null, ['id' => $id]);
switch (gettype($this->source)) {
case 'object':
case 'array':
$this->source = ArrayHelper::toArray($this->source);
$this->source = json_encode($this->source, true);
break;
}
$js = new JsExpression("\$(document).ready(function(e){var calendar = \$('#" . $id . "').calendar({events_source: " . $this->source . " }); });");
$content .= Html::tag('script', $js, ['type' => 'text/javascript']);
$this->registerPlugin(__CLASS__);
return Html::tag('div', $content, ['class' => $config['class']]);
}
示例4: convertModelToArray
public static function convertModelToArray($models)
{
if (is_array($models)) {
$arrayMode = true;
} else {
$models = array($models);
$arrayMode = false;
}
$result = [];
foreach ($models as $model) {
$attributes = ArrayHelper::toArray($model);
$relations = [];
if ($model instanceof yii\base\Model) {
foreach ($model->getRelatedRecords() as $key => $related) {
if ($model->getRelation($key)) {
if (is_array($model->{$key}) || $model->{$key} instanceof yii\base\Model) {
$relations[$key] = self::convertModelToArray($model->{$key});
} else {
$relations[$key] = $model->{$key};
}
}
}
}
$all = array_merge($attributes, $relations);
if ($arrayMode) {
array_push($result, $all);
} else {
$result = $all;
}
}
return $result;
}
示例5: actionCreate
/**
* Creates a new Sale model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($object_id = 0)
{
$model = new Sale();
if ($object_id) {
$object = Object::findOne($object_id);
if ($object) {
$temp = ArrayHelper::toArray($object->sale);
unset($temp['id']);
foreach ($temp as $k => $v) {
$model->{$k} = $v;
}
}
$model->view_ids = ArrayHelper::toArray($object->sale->view_ids);
$model->facility_ids = ArrayHelper::toArray($object->sale->facility_ids);
}
$model->status = 1;
$model->sold = 1;
$model->code = rand(100000000, 999999999);
for ($i = 1; $i <= Lang::find()->count(); $i++) {
$model_content[$i] = new SaleLang();
$model_content[$i]['lang_id'] = $i;
$model_content[$i]['id'] = 0;
}
if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content) && $model->validate() && $model->district_id > 0) {
$model->save();
foreach ($model_content as $key => $content) {
$content->id = $model->id;
$content->lang_id = $key;
$content->save(false);
}
return $this->redirect(['update', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'model_content' => $model_content]);
}
}
示例6: actionPage
/**
* Render page, query string 's' indicates that get page record regardless of published status
*/
public function actionPage($id = '')
{
$isPreview = \Yii::$app->request->get('s', 0);
if (!empty($id)) {
$id = new \MongoId($id);
$page = Page::getPage($id, !!$isPreview);
if (empty($page) || empty($page->url)) {
$this->redirect(self::NOT_FOUND_PAGE_PATH);
}
if (empty($page['color'])) {
$page['color'] = \Yii::$app->params['micrositeDefaultColor'];
}
if (empty($page->cpts) || $isPreview) {
$cpts = PageComponent::getAllComponents($id);
$page->cpts = ArrayHelper::toArray($cpts);
}
$sdk = Yii::$app->wechatSdk;
$sdk->refererUrl = $sdk->refererDomain . 'msite/page/' . $id;
$signPackage = $sdk->getSignPackage();
$actionView = $this->getView();
$actionView->registerJsFile('https://res.wx.qq.com/open/js/jweixin-1.0.0.js');
$this->view->params['page'] = $page;
$this->view->params['pageRGBColor'] = join(',', StringUtil::hex2rgb($page['color']));
$this->layout = self::PAGE_PATH;
$this->registerPageResource($isPreview);
$params = ['signPackage' => $signPackage, 'components' => $page->cpts, 'page' => ['title' => $page->title, 'desc' => $page->description, 'url' => $page->url, 'isCover' => $page->type === Page::TYPE_COVER]];
if (BrowserUtil::isWeiboBrower() || BrowserUtil::isWeixinBrowser()) {
$params['hideTitle'] = true;
}
return $this->render(self::PAGE_PATH, $params);
} else {
return $this->render(self::NOT_FOUND_PAGE_PATH);
}
}
示例7: save
/**
* @return $this
* @throws NotSupportedException
*/
public function save()
{
$paramsFilePath = \Yii::$app->paramsManager->paramsFilePath($this->paramsType());
file_put_contents($paramsFilePath, '<?php return ' . var_export(ArrayHelper::toArray($this), true) . ';');
@chmod($paramsFilePath, 0775);
return $this;
}
示例8: afterRegister
/**
* 用户注册事件处理句柄
* @param object $event
*/
public function afterRegister($event)
{
//处理积分
$creditTask = new CreditTask();
$creditTask->task_name = TaskConstant::REGISTER_CREDITS_TASK;
//任务名称
$creditTask->scebario = TaskConstant::REGISTER_TASK_SCEBARIO;
//场景
$creditTask->data = ['user_id' => $event->userId, 'credits' => 500];
CreditsService::getService()->push(ArrayHelper::toArray($creditTask));
//处理耕币
$forumTask = new ForumTask();
$forumTask->task_name = TaskConstant::REGISTER_FORUM_TASK;
$forumTask->scebario = TaskConstant::REGISTER_TASK_SCEBARIO;
//场景
$forumTask->data = ['user_id' => $event->userId, 'forum' => 500];
ForumService::getService()->push(ArrayHelper::toArray($forumTask));
//用户邀请码
$invitationTask = new InvitationCodeTask();
$invitationTask->task_name = TaskConstant::REGISTER_FORUM_TASK;
$invitationTask->scebario = TaskConstant::REGISTER_TASK_SCEBARIO;
//场景
$invitationTask->data = ['user_id' => $event->userId];
InvitationService::getService()->push(ArrayHelper::toArray($invitationTask));
}
示例9: getListCategories
/**
* @inheritdoc
*/
public static function getListCategories()
{
$arr = ArrayHelper::toArray(self::find()->active()->select('id, title')->orderBy('title ASC')->all());
array_unshift($arr, ['id' => NULL, 'title' => Yii::t('app/categories', 'Without Category')]);
$arr2 = ArrayHelper::map($arr, 'id', 'title');
return $arr2;
}
示例10: GetItems
public function GetItems($model_id = 0)
{
if ($model_id !== 0) {
$find = self::find()->select(['name', 'title', 'class', 'index'])->where(["model_id" => $model_id])->orderBy(['index' => 'ASC'])->all();
$result = ArrayHelper::toArray($find);
return $result;
}
}
示例11: toArray
/**
* @return array
*/
public function toArray()
{
if ($this->isOk()) {
return ['result' => static::RESULT_OK, 'data' => $this->data ? ArrayHelper::toArray($this->data) : null];
} else {
return ['result' => static::RESULT_OK, 'msg' => $this->msg ? $this->msg : null, 'data' => $this->data ? ArrayHelper::toArray($this->data) : null];
}
}
示例12: getAuthorsForDropDownList
/**
* @return array(['id' => 'fullname])
*/
public static function getAuthorsForDropDownList()
{
$authorsModels = Authors::find()->all();
$authors = ArrayHelper::toArray($authorsModels, ['app\\models\\Authors' => ['id', 'fullname' => function ($model) {
return "{$model->firstname} {$model->lastname}";
}]]);
return ArrayHelper::map($authors, 'id', 'fullname');
}
示例13: onMessage
/**
* Process a message and run a requested function from a client
*
* @param ConnectionInterface $client connection object
* @param string $msg json message recieved from a client
*/
public function onMessage(ConnectionInterface $client, $msg)
{
$obj = json_decode($msg);
$method = $obj->method;
$params = ArrayHelper::toArray($obj->data);
array_unshift($params, $client);
call_user_func_array([$this, $method], $params);
}
示例14: saveForm
public function saveForm()
{
if (!$this->validate()) {
return false;
}
Option::updateOption(ArrayHelper::toArray($this));
return true;
}
示例15: it_should_be_able_to_convert_existing_node_to_root
/**
* @test
*/
public function it_should_be_able_to_convert_existing_node_to_root()
{
$node = $this->tree('node_1_1');
self::assertEquals(1, Tree::find()->roots()->count(), 'there is only one root for now');
self::assertTrue($node->makeRoot(), 'node is transformed to root');
self::assertEquals(2, Tree::find()->roots()->count(), 'new root has been created');
$childData = [4 => ['id' => 4, 'label' => 'node 1.1.1', 'path' => '.2.', 'level' => 1, 'position' => 1]];
self::assertEquals($childData, ArrayHelper::toArray($node->getChildren()), 'node child got level up');
}