laravel5 namespace problem
黄舟
黄舟 2017-05-16 16:56:19
0
2
519

Use is required when using class methods in laravel5,
Can you import them all at once?

I often don’t know which one to introduce

<?php namespace App\Http\Controllers;
use Request;
use Session;
use View;
use DB;
class TestController extends Controller {

    public function getIndex()
    {
        $data['name']='laravel';
        return View::make('hi',$data);
    }

    public function getName(){
        $rs=DB::select("select * from cf_user");
        print_r($rs);
    }
    //获取ip地址
    public function getIp(){
        echo Request::ip();
    }

    //
    public function getTest(){
        echo 123;
    }

    public function getDetail($id){
        echo $id;
    }
    public function getFullUrl(){
        echo Request::fullUrl();
    }

    public function getType(){
        echo Request::method();
    }

    public function getRoot(){
        echo Request::root();
    }

    public function getUrl(){
        echo Request::url();
    }

    public function getSe(){
        print_r(Request::segments());
    }

    public function getAll(){
        print_r(Request::all());
    }
    public function getH(){
        print_r(Request::header('cookie'));
    }
    public function getServer(){
        print_r(Request::server());
    }

    public function getSession(){
        print_r(Request::session());
    }
}
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
習慣沉默
php//直接顶级命名空间
 public function getName(){
        $rs=\DB::select("select * from cf_user");
        print_r($rs);
    }
//获取ip地址
    public function getIp(){
        echo \Request::ip();
    }

我想大声告诉你

Introduce whatever you want to use, otherwise what you are doing is equivalent to importing all the project file contents into one file. What is the difference? Although it is troublesome, this is a process that must be adapted to

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template