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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 閃存消息(Flashing Messages) # 閃存消息(Flashing Messages) 閃存消息用于通知用戶關于他/她產生的動作狀態,或者簡單地為用戶顯示一此信息。這類消息可以使用這個組件來生成。 ### 適配器(Adapters) 這個組件使用了適配器來定義消息傳遞給Flasher后的行為: 適配器描述APIDirect直接輸出傳遞給flasher的消息[*Phalcon\\Flash\\Direct*](#)Session將消息臨時存放于會話中,以便消息可以在后面的請求中打印出來[*Phalcon\\Flash\\Session*](#)### 使用(Usage) 通常閃存消息都是來自服務容器的請求,如果你正在使用 [*Phalcon\\DI\\FactoryDefault*](#) ,那么 [*Phalcon\\Flash\\Direct*](#) 將會作為 “flash” 服務自動注冊: ``` <pre class="calibre14">``` <?php use Phalcon\Flash\Direct as FlashDirect; // 建立flash服務 $di->set('flash', function () { return new FlashDirect(); }); ``` ``` 這樣的話,你便可以在控制器或者視圖中通過在必要的片段中注入此服務來使用它: ``` <pre class="calibre14">``` <?php use Phalcon\Mvc\Controller; class PostsController extends Controller { public function indexAction() { } public function saveAction() { $this->flash->success("The post was correctly saved!"); } } ``` ``` 目前已支持的有四種內置消息類型: ``` <pre class="calibre14">``` <?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."); ``` ``` 你可以用你自己的類型來添加消息: ``` <pre class="calibre14">``` <?php $this->flash->message("debug", "this is debug message, you don't say"); ``` ``` ### 輸出信息(Printing Messages) 發送給flash服務的消息將會自動格式成html: ``` <pre class="calibre14">``` <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的類將會自動添加到div中。這些類允許你定義消息在瀏覽器上的圖形表現。此CSS類可以被重寫,例如,如果你正在使用Twitter的bootstrap,對應的類可以這樣配置: ``` <pre class="calibre14">``` <?php use Phalcon\Flash\Direct as FlashDirect; // 利用自定義的CSS類來注冊flash服務 $di->set('flash', function () { $flash = new FlashDirect( array( 'error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning' ) ); return $flash; }); ``` ``` 然后消息會是這樣輸出: ``` <pre class="calibre14">``` <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重定向,那么則需要存放于會話中: ``` <pre class="calibre14">``` <?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( array( "action" => "index" ) ); } } ``` ``` 或者使用一個HTTP重定向: ``` <pre class="calibre14">``` <?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"); } } ``` ``` 在這種情況下,你需要手動在交互的視圖上打印消息: ``` <pre class="calibre14">``` <!-- app/views/contact/index.phtml --> <p><?php $this->flashSession->output() ?></p> ``` ``` “flashSession”屬性是先前在依賴注入容器中設置的閃存。為了能成功使用flashSession消息者,你需要先啟動 [*session*](#) 。 | - [索引](# "總目錄") - [下一頁](# "使用 Session 存儲數據(Storing data in Session)") | - [上一頁](# "生成 URL 和 路徑(Generating URLs and Paths)") |
                  <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>

                              哎呀哎呀视频在线观看