OOP public variable problem
Can someone please help for some reason i can echo and set the file and department variables in my export function but when i try to call them in exportdata they are null.
Class customersController Extends baseController {
public $file;
public $department;
public function export() {
$this->registry->template->title = 'Ainsworthstudio - Export Customer Info';
$this->registry->model->createModel('db', 'db');
$this->registry->model->createModel('customers', 'customers');
$this->registry->model->getModel('db')->addConnection("localhost", "sdgsdg", "sdg0", "sdg");
$data = $this->registry->model->getModel('customers')->getDepartments();
while(list($k, $v)=each($data))
$$k = $v;
$this->registry->template开发者_如何学Go->departments = $data;
$this->registry->template->show('customers_export');
}
public function exportcheck() {
if(!empty($_POST['filename'])) {
$this->file = $_POST['filename'];
$this->department = $_POST['depart'];
echo "<div class='error_message'>Exported Successfully</div>";
echo $this->file;
echo $this->department;
echo 'success';
} else {
echo "<div class='error_message'>Wrong Username or Password</div>";
exit();
}
}
public function exportdata() {
return $this->file;
return $this->department;
echo $this->department;
}
}
Your problem is here:
public function exportdata() {
return $this->file;
return $this->department;
echo $this->department;
}
You're returning the value of $this->file
not echoing.
If you try echo $myCustomersController->exportdata()
you'll see it echo the value of $this->file
If you want to echo
the values remove the return
s
public function exportdata() {
echo $this->file;
echo $this->department;
}
精彩评论