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
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Wed May 23, 2007 9:30 am
Hi guys...
i have the following code that is loaded into an iframe.
Code: Select all
$page_content = isset($_SESSION['MenuItem'])? $_SESSION['MenuItem'] : new Page(); // $_SESSION is a populated new Page()
$column = isset($_GET['column'])? $_GET['column'] : 'left';
// submit information
if(isset($_GET['add_content'])){
$content = array('contentid'=>$_GET['ContentID']
,'contentname'=>$_GET['ContentName']
,'filetype'=>$_GET['FileType']
,'section'=>$_GET['Section']
);
//print_r($page_content);
$page_content->add_column_content($content,$column,$order= false);
}
a $_GET['add_content'] is passed via a javascript initiated reload(iframe.src) of the iframe causing it to "add" the content to the variable $page_content (new Page() SESSION) $page_content is a variable that is either instantiated as a Class or is a SESSION CLass of new Page()
the class has a method "add_column_content"....however when the above code run....although a "print_r" reveals that the class object exists...but i get a
Call to undefined method stdClass::add_column_content()
what gives? as the class is being instantiated and the class is being called before the session_start()
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed May 23, 2007 9:32 am
Which version of php do you use?
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Wed May 23, 2007 9:35 am
volka wrote: Which version of php do you use?
PHP 5
y?....
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed May 23, 2007 9:41 am
It would appear that the session loaded object didn't materialize as expected -- the class wasn't loaded at the time.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed May 23, 2007 9:42 am
because I wanted to know if all reflection classes/methods are available for a test script. php 5.1.6+ is needed for that.
anyway, please try
Code: Select all
//print_r($page_content);
echo '<pre>', var_export(get_class($page_content), true), "</pre>\n";
echo '<pre>', var_export(get_class_methods($page_content), true), "</pre>\n";
$page_content->add_column_content($content,$column,$order= false);what does it print?
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Wed May 23, 2007 9:45 am
feyd wrote: It would appear that the session loaded object didn't materialize as expected -- the class wasn't loaded at the time.
well thats an odd statement...seeing that
Code: Select all
$page_content = isset($_SESSION['MenuItem'])? $_SESSION['MenuItem'] : new Page(); // $_SESSION['MenuItem'] is a populated new Page()
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Wed May 23, 2007 9:52 am
Volka....
i did what you suggested and i got
strange...as it should have returned something right? on first load of the iframe...its content actually instantiates the session and does a "header()" to reload the said page...in order to realise that a session is created...its results is true as i get a output of the sessions variables content....
However when i try the $_GET['add_content']
this is where i get the problem....
is my reloading of the iframe.src clearing the session and restarting it?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed May 23, 2007 9:59 am
if you currently have
Code: Select all
session_start();
require 'page.php'; // where the class Page is definedchange it to
Code: Select all
require 'page.php';
session_start();The class definition muss be present before an object of that calss can be restored from the session data.
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Wed May 23, 2007 10:02 am
volka wrote: The class definition muss be present before an object of that class can be restored from the session data.
yes it is...otherwise at first load it would have given me an error...
the undefined error happens when i pass a $_GET['add_content']
mind u...that how i pass the parameter is via a frame.src to which i append the url of the frame.src with the parameter...this reloads the iframe
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed May 23, 2007 10:15 am
kendall wrote: volka wrote: The class definition muss be present before an object of that class can be restored from the session data.
yes it is...otherwise at first load it would have given me an error...
not necessarily.
kendall wrote: the undefined error happens when i pass a $_GET['add_content']
Yes, that is the condition for calling the object's method.
What does
Code: Select all
echo 'MenuItem: ', isset($_SESSION['MenuItem']) ? 'set':'not set', "<br />\n";
$page_content->add_column_content($content,$column,$order= false);print?
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Tue Jul 17, 2007 3:26 pm
volka wrote:
What does
Code: Select all
echo 'MenuItem: ', isset($_SESSION['MenuItem']) ? 'set':'not set', "<br />\n";
$page_content->add_column_content($content,$column,$order= false);print?
The code
Code: Select all
if(isset($_SESSION['MenuItem'])){
print ("ok");
}else{
print("fail");
}
prints ok...and i get the output of the session
but when i do a....
Code: Select all
if(is_a($_SESSION['MenuItem'],'Page')){ // checks if is a new Page()
print ("ok");
}else{
print("fail");
}
it prints "fail" but i get the output of the session...its class variables
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Jul 17, 2007 5:11 pm
It's still probably:
feyd wrote: It would appear that the session loaded object didn't materialize as expected -- the class wasn't loaded at the time.
The class definition must be present when session_start() is called - each time session_start() is called.
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Tue Jul 17, 2007 7:25 pm
volka...
thats the funny thing about it....it is other wise why am i still accessing the $_SESSION['MenuItem']'s variables?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Jul 17, 2007 7:38 pm
I don't understand your last post.