how to forward this object to another page ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
czy11421
Forum Newbie
Posts: 7
Joined: Sat Dec 26, 2009 9:03 pm

how to forward this object to another page ?

Post by czy11421 »

how to forward an object to another page ? I tried to put object to Request, but doesn't work.

In controller page, I have

Code: Select all

 
  $myObj = new MyObj();
 
  $_REQUEST["myObj"] = $myObj ;
        
 header("location:../page/p1.php");
 
in p1.php, I have

Code: Select all

 
 <form  action="">
          <input  value="<?php echo $_REQUEST["myObj"]->getCreateDate(); ?>" type="text" />
   </form>
 
This coding doesn't work. If we don't use Session, how to forward this object to another page ?

Thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to forward this object to another page ?

Post by requinix »

Either you use sessions or you recreate the object on the second page (by passing whatever information is necessary in the URL).
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: how to forward this object to another page ?

Post by manohoo »

I'd follow tsairis advice, just create a new object in p1.php.

Just for the sake of learning, if you serialize an object

Code: Select all

$myObjSerialized = serialize($myObj);
header("location:../page/p1.php?object=$myObjSerialized");
Then you can unserialize it in p1.php:

Code: Select all

$myObjUnserialized= unserialize($_REQUEST['object']);
// Now, let's take a look at the object
echo "<pre">;
var_dump($myObjUnserialized);
... but the results are not always predictable. Give it a try, compare the before and after objects and decide if it works for you.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: how to forward this object to another page ?

Post by Darhazer »

You should include the class definition of the object before trying to unserialize it. And storing the variable in session is the usual way.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: how to forward this object to another page ?

Post by AbraCadaver »

Darhazer wrote:You should include the class definition of the object before trying to unserialize it. And storing the variable in session is the usual way.
+1
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply