在PHP控制器中更改全局变量

时间:2018-12-14 13:30:27

标签: php laravel variables controller controls

我尝试更改全局变量$ winLogBook的值,但它似乎仅在本地无法全局工作。

public $winLogBook = "nothing";

public function setLog(){
      $this->winLogBook = "somethin";
    }

我的输出:什么都没有

$controller->setLog();    
echo $this->winLogBook;

我的完整代码:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\fieldModel;

class losOpController extends Controller
{
public $winLogBook = "nothing";
public function setLog(){
      $this->winLogBook = "somethin";
        }
public function printLogBook(){
        echo $this->winLogBook;
    }
}

先谢谢您!

0 个答案:

没有答案