I've been working on a simple class that kindo build on the MVC framework. I'm trying to learn a lot about programming. I'm having a problem with scope. It has quite a simple PHP script and need access a variable birth
.
class NUMK {
public $plugin_name;
public $version;
public function __construct( $plugin_name, $version) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->loadClient();
}
public function pager(){
if(isset($_POST['birth'])){
$birth = $_POST['birth'];
require_once '/html/view/index.php';
};
}
}
How can I access $birth
in /html/view/index.php
. I tried global $birth
. No luck.
Thanks
答案 0 :(得分:0)
You could use the extract function. It receives an array and import variables into the current symbol table, after that you can reference it in the required file, as $birth.
Example:
public function pager(){
if(isset($_POST['birth'])){
$data = array();
$data['birth'] = $_POST['birth'];
extract($data, EXTR_REFS);
require_once '/html/view/index.php';
};
}