当前位置: 首页>>代码示例>>PHP>>正文


PHP Utils::arrayFlatten方法代码示例

本文整理汇总了PHP中Grav\Common\Utils::arrayFlatten方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::arrayFlatten方法的具体用法?PHP Utils::arrayFlatten怎么用?PHP Utils::arrayFlatten使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grav\Common\Utils的用法示例。


在下文中一共展示了Utils::arrayFlatten方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onPagesInitialized

 /**
  * Initialize form if the page has one. Also catches form processing if user posts the form.
  */
 public function onPagesInitialized()
 {
     $submitted = false;
     if ($this->isAdmin() && !empty($_POST)) {
         $page = $this->grav['page'];
         if (!$page) {
             return;
         }
         $header = $page->header();
         if (isset($header->form) && is_array($header->form)) {
             $this->active = true;
             // Create form
             $this->form = new Form($page);
             $this->enable(['onFormProcessed' => ['onFormProcessed', 0], 'onFormValidationError' => ['onFormValidationError', 0]]);
             $this->form->post();
         }
     } elseif ($this->forms) {
         $this->enable(['onTwigPageVariables' => ['onTwigVariables', 0], 'onTwigSiteVariables' => ['onTwigVariables', 0], 'onFormFieldTypes' => ['onFormFieldTypes', 0]]);
         // Regenerate list of flat_forms if not already populated
         if (empty($this->flat_forms)) {
             $this->flat_forms = Utils::arrayFlatten($this->forms);
         }
         // Save the current state of the forms to cache
         if ($this->recache_forms) {
             $this->grav['cache']->save($this->cache_id, [$this->forms, $this->flat_forms]);
         }
         $this->active = true;
         // Handle posting if needed.
         if (!empty($_POST)) {
             $this->enable(['onFormProcessed' => ['onFormProcessed', 0], 'onFormValidationError' => ['onFormValidationError', 0]]);
             $current_form_name = $this->getFormName($this->grav['page']);
             $this->json_response = [];
             if ($form = $this->getFormByName($current_form_name)) {
                 if ($this->grav['uri']->extension() === 'json') {
                     $this->json_response = $form->uploadFiles();
                 } else {
                     $form->post();
                     $submitted = true;
                 }
             } elseif (isset($this->grav['page']->header()->form)) {
                 $form = new Form($this->grav['page']);
                 $form->post();
                 $submitted = true;
             }
         }
         // Clear flash objects for previously uploaded files
         // whenever the user switches page / reloads
         // ignoring any JSON / extension call
         if (is_null($this->grav['uri']->extension()) && !$submitted) {
             // Discard any previously uploaded files session.
             // and if there were any uploaded file, remove them from the filesystem
             if ($flash = $this->grav['session']->getFlashObject('files-upload')) {
                 $flash = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($flash));
                 foreach ($flash as $key => $value) {
                     if ($key !== 'tmp_name') {
                         continue;
                     }
                     @unlink($value);
                 }
             }
         }
     }
 }
开发者ID:getgrav,项目名称:grav-plugin-form,代码行数:66,代码来源:form.php


注:本文中的Grav\Common\Utils::arrayFlatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。