<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 閃存消息(Flashing Messages) 閃存消息用于通知用戶關于他/她產生的動作狀態,或者簡單地為用戶顯示一此信息。 這類消息可以使用這個組件來生成。 ## 適配器(Adapters) 這個組件使用了適配器來定義消息傳遞給Flasher后的行為: | 適配器 | 描述 | API | | --- | --- | --- | | Direct | 直接輸出傳遞給flasher的消息 | [Phalcon\\Flash\\Direct](http://docs.iphalcon.cn/api/Phalcon_Flash_Direct.html) | | Session | 將消息臨時存放于會話中,以便消息可以在后面的請求中打印出來 | [Phalcon\\Flash\\Session](http://docs.iphalcon.cn/api/Phalcon_Flash_Session.html) | ## 使用(Usage) 通常閃存消息都是來自服務容器的請求. 如果你正在使用[Phalcon\\Di\\FactoryDefault](http://docs.iphalcon.cn/api/Phalcon_Di_FactoryDefault.html), 那么[Phalcon\\Flash\\Direct](http://docs.iphalcon.cn/api/Phalcon_Flash_Direct.html)將會作為 “flash” 服務自動注冊 和[Phalcon\\Flash\\Session](http://docs.iphalcon.cn/api/Phalcon_Flash_Session.html)將會作為 “flashSession” 服務自動注冊. You can also manually register it: ~~~ <?php use Phalcon\Flash\Direct as FlashDirect; use Phalcon\Flash\Session as FlashSession; // 建立flash服務 $di->set( "flash", function () { return new FlashDirect(); } ); // 建立flashSession服務 $di->set( "flashSession", function () { return new FlashSession(); } ); ~~~ 這樣的話,你便可以在控制器或者視圖中通過在必要的片段中注入此服務來使用它: ~~~ <?php use Phalcon\Mvc\Controller; class PostsController extends Controller { public function indexAction() { } public function saveAction() { $this->flash->success("The post was correctly saved!"); } } ~~~ 目前已支持的有四種內置消息類型: ~~~ <?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."); ~~~ 你可以用你自己的類型來添加消息: ~~~ <?php $this->flash->message("debug", "this is debug message, you don't say"); ~~~ ## 輸出信息(Printing Messages) 發送給flash服務的消息將會自動格式成html: ~~~ <div class="errorMessage">too bad! the form had errors</div> <div class="successMessage">yes!, everything went very smoothly</div> <div class="noticeMessage">this a very important information</div> <div class="warningMessage">best check yo self, you're not looking too good.</div> ~~~ 正如你看到的,CSS的類將會自動添加到:code:[`](http://docs.iphalcon.cn/reference/flash.html#id1)`中。這些類允許你定義消息在瀏覽器上的圖形表現。 此CSS類可以被重寫,例如,如果你正在使用Twitter的Bootstrap,對應的類可以這樣配置: ~~~ <?php use Phalcon\Flash\Direct as FlashDirect; // 利用自定義的CSS類來注冊flash服務 $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; } ); ~~~ 然后消息會是這樣輸出: ~~~ <div class="alert alert-danger">too bad! the form had errors</div> <div class="alert alert-success">yes!, everything went very smoothly</div> <div class="alert alert-info">this a very important information</div> <div class="alert alert-warning">best check yo self, you're not looking too good.</div> ~~~ ## 絕對刷送與會話(Implicit Flush vs. Session) 依賴于發送消息的適配器,它可以立即產生輸出,也可以先臨時將消息存放于會話中隨后再顯示。 你何時應該使用哪個?這通常依賴于你在發送消息后重定向的類型。例如, 如果你用了“轉發”則不需要將消息存放于會話中,但如果你用的是一個HTTP重定向,那么則需要存放于會話中: ~~~ <?php use Phalcon\Mvc\Controller; class ContactController extends Controller { public function indexAction() { } public function saveAction() { // 存儲POST // 使用直接閃存 $this->flash->success("Your information was stored correctly!"); // 轉發到index動作 return $this->dispatcher->forward( [ "action" => "index" ] ); } } ~~~ 或者使用一個HTTP重定向: ~~~ <?php use Phalcon\Mvc\Controller; class ContactController extends Controller { public function indexAction() { } public function saveAction() { // 存儲POST // 使用會話閃存 $this->flashSession->success("Your information was stored correctly!"); // 返回一個完整的HTTP重定向 return $this->response->redirect("contact/index"); } } ~~~ 在這種情況下,你需要手動在交互的視圖上打印消息: ~~~ <!-- app/views/contact/index.phtml --> <p><?php $this->flashSession->output() ?></p> ~~~ “flashSession”屬性是先前在依賴注入容器中設置的閃存。 為了能成功使用flashSession消息者,你需要先啟動[session](http://docs.iphalcon.cn/reference/session.html)。
                  <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>

                              哎呀哎呀视频在线观看