这是我在 codeigniter 的库文件夹中的自定义类
class Commonlib {
public function __construct()
{
$ci=& get_instance();
$ci->load->database();
}
function getcountries(){
return $ci->db->get("countries")->result();
}
function cities(){
return $ci->db->get("cities")->result();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的观点
$results=$this->commonlib->getcountries();
foreach ($results as $row)
{
echo '<a href="#">'.$row->country .'</a><br>';
}
Run Code Online (Sandbox Code Playgroud)
错误是严重性:通知消息:未定义变量:ci 如何在库构造函数中加载数据库
如何从用户IP地址获取国家/地区名称
我有用户的IP地址我在用户IP地址获取用户的国家名称如何在PHP?
function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
Run Code Online (Sandbox Code Playgroud) 未定义的属性:Illuminate\Validation\Validator :: $ laravel中的错误
这里是我的控制器文件如何解决它我认为这里问题是任何命名空间在哪里是我不知道请指导我
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Route;
use Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;
use App\models\Designation;
use Validator;
use Illuminate\Support\Facades\Response;
class Cdesigination extends Controller
{
public $flight;
public function __construct(){
$this->flight = new Designation;
}
public function index()
{
return view('designation');
}
public function techer(Request $request) {
$Validator =Validator::make(array(
'name'=>Input::get('name'),
'detail'=>Input::get('detail')
),array(
'name' => 'required',
'detail' => 'required'
));
if ($Validator->fails()) {
return Response::json([
'success'=>false,
'error' =>$Validator->errors->toArray()
]);
}
else{
$this->flight->name = $request->name;
$this->flight->detail = $request->detail;
$this->flight->save();
return Response::json([ …Run Code Online (Sandbox Code Playgroud)