<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # 閃存消息 Flash消息用于向用戶通知他/她所做的操作的狀態,或者僅向用戶顯示信息。可以使用此組件生成這些類型的消息。 ## 適配器 此組件使用適配器在傳遞給Flasher后定義消息的行為: | 適配器 | 描述 | API | | :-----: | :----------------------------------------------------: | :-------------------: | | Direct | 直接輸出傳遞給閃存器的消息 | Phalcon\\Flash\\Direct | | Session | 暫時將消息存儲在會話中,然后可以在下一個請求中打印消息 | Phalcon\\Flash\\Session | ## 使用 通常,從服務容器請求Flash消息傳遞服務。如果您正在使用 `Phalcon\\Di\\FactoryDefault`,則 `Phalcon\\Flash\\Direct` 會自動注冊為flash 服務, `Phalcon\\Flash\\Session` 會自動注冊為 `flashSession` 服務。您也可以手動注冊它: ```php <?php use Phalcon\\Flash\\Direct as FlashDirect; use Phalcon\\Flash\\Session as FlashSession; // 設置閃存服務 $di->set( 'flash', function () { return new FlashDirect(); } ); // Set up the flash session service $di->set( 'flashSession', function () { return new FlashSession(); } ); ``` 這樣,您可以在控制器或視圖中使用它: ```php <?php use Phalcon\\Mvc\\Controller; class PostsController extends Controller { public function indexAction() { } public function saveAction() { $this\->flash\->success('The post was correctly saved!'); } } ``` 支持四種內置消息類型: ```php <?php $this->flash->error('too bad! the form had errors'); $this->flash->success('yes!, everything went very smoothly'); $this->flash->notice('this a very important information'); $this->flash->warning("best check yo self, you're not looking too good."); ``` 您還可以使用 `message()` 方法添加具有您自己類型的消息: ```php <?php $this->flash->message('debug', "this is debug message, you don't say"); ``` ## 打印消息 發送到閃存服務的消息將自動使用HTML格式化: ```php too bad! the form had errors yes!, everything went very smoothly this a very important information best check yo self, you're not looking too good. ``` 如您所見,CSS類會自動添加到 `` 中。這些類允許您在瀏覽器中定義消息的圖形表示。可以覆蓋CSS類,例如,如果您使用的是Twitter Bootstrap,則可以將類配置為: ```php <?php use Phalcon\\Flash\\Direct as FlashDirect; // Register the flash service with custom CSS classes $di->set( 'flash', function () { $flash = new FlashDirect( [ 'error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning', ] ); return $flash; } ); ``` 然后消息將打印如下: ```php too bad! the form had errors yes!, everything went very smoothly this a very important information best check yo self, you're not looking too good. ``` ## 隱式刷新與Session 根據用于發送消息的適配器,它可以直接生成輸出,或者暫時將消息存儲在會話中以便稍后顯示。你應該什么時候使用?這通常取決于您在發送郵件后執行的重定向類型。例如,如果您沒有必要將轉發存儲在會話中,但是如果您執行HTTP重定向,則需要將它們存儲在會話中: ```php <?php use Phalcon\\Mvc\\Controller; class ContactController extends Controller { public function indexAction() { } public function saveAction() { // Store the post // Using direct flash $this->flash->success('Your information was stored correctly!'); // Forward to the index action return $this->dispatcher->forward([ 'action' => 'index']); } } ``` 或者使用HTTP重定向: ```php <?php use Phalcon\\Mvc\\Controller; class ContactController extends Controller { public function indexAction() {} public function saveAction(){ // Store the post // Using session flash $this->flashSession->success('Your information was stored correctly!'); // Make a full HTTP redirection return $this->response->redirect('contact/index'); } } ``` 在這種情況下,您需要在相應的視圖中手動打印消息: ```php flashSession->output() ?> ``` 屬性 flashSession 是先前將flash設置到依賴項注入容器中的方式。您需要首先啟動session才能成功使用flashSession消息。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看