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());
}
}
習慣沉默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(); }
我想大声告诉你2017-05-16 16:58:19
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