suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Laravel5-Namespace-Problem

Use ist erforderlich, wenn Klassenmethoden in Laravel5 verwendet werden,
Kann es auf einmal eingeführt werden?

Ich weiß oft nicht, welches ich vorstellen soll

<?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());
    }
}
黄舟黄舟2826 Tage vor531

Antworte allen(2)Ich werde antworten

  • 習慣沉默

    習慣沉默2017-05-16 16:58:19

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

    Antwort
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 16:58:19

    当你要用到什么就引入什么呗,不然你这个做法不就相当于把所有项目文件内容全都引到一个文件内容有什么区别嘛,虽然麻烦,但是这是必须要适应地过程

    Antwort
    0
  • StornierenAntwort