久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel 私有變量在 Controller 中的兩個方法之間共享

Laravel private variable shared between two methods in Controller(Laravel 私有變量在 Controller 中的兩個方法之間共享)
本文介紹了Laravel 私有變量在 Controller 中的兩個方法之間共享的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

如何在 Laravel Controller 中使用私有變量,并在兩個方法之間共享該變量值.(設置在一個使用它在另一個).

How to use private variable in Laravel Controller, and share that variable value between two methods. (Set it in one use it in another).

推薦答案

您說的是單個控制器,對嗎?所以我假設這就是你的意思:

You're talking about one single controller, right? So I'll assume that this what you mean:

class ControllerController extends Controller {

    private $variable;

    public function __construct($whatever)
    {
        $this->variable = $whatever;
    }

    public function method1($newValue)
    {
        $this->variable = $newValue;
    }

    public function method2()
    {
        return $this->variable;
    }

}

如果你在同一個請求中做事情,你可以

If you are doing thing in the same request, you can

$this->method1('newvalue');

echo $this->method2();

它會打印newvalue.

如果您在請求之間執行此操作,您需要記住您的應用程序在請求重新啟動后結束,因此您需要將其存儲在某處,例如在 Session 變量中:

If you are doing it between requests, you need to remember that your application ends after a request a restart in a new one, so you'll need to store it somewhere, like in a Session variable:

Session::put('variable', $newvalue);

然后

Session::get('variable');

或者您可以使用返回方法所需的值進行重定向:

Or you can redirect with the value you need to get back in your method:

Redirect::to('posts')->with('variable','this is a new value');

然后在第二個

Session::get('variable');

這篇關于Laravel 私有變量在 Controller 中的兩個方法之間共享的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 午夜无码国产理论在线 | 成人一区二区三区在线观看 | 天天干亚洲 | 免费观看一级黄色录像 | 欧美国产中文 | 日本一区二区高清不卡 | 伊人性伊人情综合网 | 久久99国产精品 | 免费国产视频 | 二区成人| 国产精品毛片av一区 | 亚洲男人天堂av | 毛片1 | 欧美6一10sex性hd | 国产一区h | 综合一区二区三区 | 日韩久久精品视频 | 国产黄色大片在线观看 | 日韩免费一区 | 欧美综合自拍 | 精品99在线| 国产在线一区二区三区 | 欧美精品成人一区二区三区四区 | 久久一区二区精品 | 国产视频一视频二 | 日韩精品人成在线播放 | 亚洲国产欧美在线人成 | 国产精品一区二区三区四区 | 久久精品国产精品青草 | 在线观看av网站 | 成人影院在线视频 | 有码一区 | 国内精品久久影院 | 日日夜夜操天天干 | 日韩在线观看一区 | 欧美一级片在线观看 | 伊人伊人伊人 | 欧美人妇做爰xxxⅹ性高电影 | 国产三区在线观看视频 | 久久久久综合 | 亚洲国产精品91 |