當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。