控制器中未定义的变量

时间:2016-11-18 09:50:58

标签: php codeigniter-3

我有一个名为Job_search的控制器 在我的Job_search.php中,我声明了一些变量:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class Job_search extends CI_Controller {

public $keyword='Driver';
public $location='KL__ Kerala KT__ Kottayam Vaikom';
public $district='78';
public $listing_type = 'Job';
public $listings_per_page = '10';
public $page='1';

public function __construct() {
    parent::__construct();
    $this->load->model('Job_search_model');
  }
public function index() {
$result=$this->Job_search_model->get_job_search_result($keyword,$location,$district,$listing_type,$listings_per_page,$page);
  }
}

我收到了这些错误:

Undefined variable: keyword

Undefined variable: location

Undefined variable: district

Undefined variable: listing_type

Undefined variable: listings_per_page

Undefined variable: page

2 个答案:

答案 0 :(得分:2)

public function index()
{
  $result=
  $this->Job_search_model->get_job_search_result(
    $this->keyword,
    $this->location,
    $this->district,
    $this->listing_type,
    $this->listings_per_page,
    $this->page);
}

试试这个,你需要$this-> infront,你在课堂上调用一个变量,所以$this->test就是如何调用它。

答案 1 :(得分:0)

您可以使用班级中的this关键字来访问它:

$this->varibale_name;