overførsel af objekter
Hej,Jeg ville gerne kunne overføre objekter mellem sider. Jeg har læst at man kan bruge sessions, som automatisk laver serialize/unserialize, men kan ikke få det til at virke.
Jeg har en index.php:
<?php
session_start();
$_SESSION['configPath'] = $_SERVER['DOCUMENT_ROOT'] . "/side/bin/config/";
include $_SESSION['configPath'] . "config.php";
$_SESSION['configuration'] = new Configuration();
$conf = $_SESSION['configuration'];
header("Location: side.php");
?>
Og en side.php
<?php
session_start();
require $_SESSION['configPath'] . "config.php";
$c = new Configuration();
printf($c->readConfig("Webserver"));
$_SESSION['configuration']->readConfig("Webserver");
//$conf = $_SESSION['configuration'];
//$conf->readConfig("Webserver");
//$conf = (Configuration) $_SESSION['configuration'];
//$conf->readConfig("Webserver");
?>
Når jeg kører index.php får jeg følgende:
127.0.0.1
Fatal error: main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Configuration" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in C:\Web\side\side.php on line 8
De to udkommenterede metoder virker heller ikke.
