Jump to content





Recent Status Updates

  • Photo
      16 Apr
    Kadence

    If you're reading this, you're on my profile and I know you're on my profile because I'm probably viewing yours.

    Show comments (6)
  • Photo
      10 Apr
    Poe

    Finally (and hopefully) i'm getting a team together that knows a little of this and a little of that; and maybe all my open source projects that are half written can begin to be released. :)

View All Updates
Photo
- - - - -

need fresh eyes.


  • Please log in to reply
2 replies to this topic

#1 zeroradius

zeroradius

    Speaks fluent binary

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,074 posts

Posted 30 December 2011 - 06:25 AM

I have this fatal error:

Call to a member function customQuery() on a non-object


Here is the code it is referring to ($data in the foreach loop)

<select name="doctor"> <?php $query = "Select id,name From doctors"; foreach($data->customQuery($query) as $doctor) { echo "<option value='".$doctor[0]."'>" . $doctor[1] . "</option>"; } ?> </select>


Here is the controller that creates the $data object

public function appointmentForm() { $data = new dbHandler("A problem has occured. Please notify an admin." ); include("views/newAppointment.php"); }


and here is the switch clause that creates the controller

case appointment: include_once("views/newAppointment.php"); $app = new appointmentController(); echo $app->appointmentForm(); break;



Just for the sake of clarity. here is another page that works the same exact way that is working (same order)!

the part that is not working in the other code but is working here

<select name="doctor"> <?php $query = "Select id,name From doctors"; foreach($data->customQuery($query) as $doctor) { echo "<option value='".$doctor[0]."'>" . $doctor[1] . "</option>"; } ?> </select>


controller

public function surgeryForm(){$data = new dbHandler("A problem has occured. Please notify an admin." ); include_once("views/newSurgery.php"); }


and the switch

case surgery: include_once("controllers/surgeryController.php"); $sur = new surgeryController(); echo $sur->surgeryForm(); break;


(I took out all the white space. the php tags on here destroyed the structure, sorry)

With the exception of file and variable names these two should be identical! I can't find were i screwed up
:crying:
  • 0
Posted Image

#2 Alexander

Alexander

    I do have 9 lives, you know.

  • Moderator
  • 3,836 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 30 December 2011 - 03:02 PM

I bet that if you look at $data it will be null or false. How are your functions changing $data? Why not $this->data? Why does your first code not use include_once when the second one does?
  • 0
Be sure to check out the new site additions - brought to you by your friendly CODECALL staff-person.
If a suggested code/method fails, informing us is less important than telling us why or what errors had occurred.

#3 zeroradius

zeroradius

    Speaks fluent binary

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,074 posts

Posted 31 December 2011 - 06:50 AM

well i don't know much about OOP just what i taught myself (have a book on the way) but i thought $this->$var was for variables that could be used for all methods in a class. I need $data to only be usable inside of the method because $data is used in almost every method in my controller class (like declaring $i = 1, you use it in the method and then throw it away)(is that not acurate?).

Originally it all used include_once. I don't remember why i changed it but i need to change it back.

The way this is set up is: Front controller (switch statement) creates an instance of the controller and calls the appointmentForm() method in the controller class and the controller creates an instance of the dbHandler class and calls the custom query method tieing the returned data into a drop down list on the View which is also gotten by the controller

I have a couple days off now so I can rest and then look at it. It's probably something simple i'm over looking.


  • 0
Posted Image