Reputation: 37
As the question, I can do that with $_SESSION
on the below code, but I would like to do that without using $_SESSION
, any suggestion ?
I am new for using oop in php.
PHP (page 1):
include './class.php';
include './next.php';
if(isset($_POST['submit'])){
$data = new myData();
$data->setTest($_POST['test']);
}
$content = '<form method="post" action="next.php">
<input type="text" name="test" id="test" value="test"/>
<input type="submit" name="submit" value="Submit"/>
</form>';
if(!empty($next)){
$content = $next;
}
echo $content;
class.php:
class myData{
function __construct($test){
***some process***
$_SESSION["test"] = $test;
}
}
next.php
$next = $_SESSION["test"];
Upvotes: 0
Views: 262
Reputation: 37
I declare a function and return back to page 1 on next.php
function showContent($content){
if(!empty($content)){
return $content;
}
return false;
}
Then on the class.php
, I declare a getter as Mr.Karim Aljandali's answer.
On the page 1 I add a line $next = showContent($data->getData());
Upvotes: 0
Reputation: 136
You could store the variable in the class and then use a getter method to get that data back. file1.php
if(isset($_POST['submit'])){
$data = new MyData($_POST['test']);
}
class MyData{
private $data = '';
function __construct($test){
***some process***
$data = $test;
}
function getData() {
return $this->data;
}
}
file2.php
include file1.php;
echo $data->getData();
Upvotes: 1