Welcome Guest, Not a member yet? Register   Sign In
help: jquery error using PHP models
#1

[eluser]ericsodt[/eluser]
I am running into something that I can not for the life of me figure out. I am running jquery and am having an issue where firebug is telling me theres an error, but the page renders fine.


Below is a simpler form of my Model
Code:
var $id;
var $f_name;
var $l_name;

function Guest(){
  parent::Model();    
}

function createObject($arr){
  $obj = $this->load->model("guest");
  $obj->id = $arr->id;
  $obj->f_name = $arr->f_name;
  $obj->l_name = $arr->l_name;

  return $obj;
}

The issue comes into play when I save my Guest Object into the session, then retrieve it to display it


Action
Code:
// get Array of Guest Objects from session
$couples = $this->session->userdata('coupleData');

// pick out one Guest Object by the guest id
$guestObj = $couples[$guestId];

// Load the food
$allFood = $this->food->getAllFood();

// display to page 'guest_profile_view'
$data = array(
         'title' => 'my title',
         'content' => 'guest_profile_view',
         'module' => 'profile',
         'guest' => $guestObj,
         'foods' => $allFood
);
$this->load->view('layout/template/siteLayout',$data);



VIEW

Code:
...
<body>

<div class="profile">
      &lt;form name="profileForm" id="profileFormId" method="post" action="profile/save/1"&gt;
        <div><span>&lt;?=$guest->f_name?&gt;</span></div>
        &lt;/form&gt;
</div>

&lt;/body&gt;
...



The rendered HTML looks fine
Code:
&lt;html&gt;
  &lt;head&gt;
     &lt;link REL="shortcut icon" HREF="http://localhost/wedding/images/favicon.ico" type="image/x-icon"&gt;&lt;/link>
    &lt;title&gt;Welcome to Dean &amp; Jessies Wedding Website&lt;/title&gt;
    
    &lt;link rel="stylesheet" type="text/css" href="http://localhost/wedding/css/global.css" &gt;&lt;/link>
    
    &lt;!--[if gte IE 5]>
    &lt;link rel="stylesheet" type="text/css" href="http://localhost/wedding/css/ie-style.css"&gt;&lt;/link>
    <![endif]--&gt;
        
  &lt;/head&gt;
    
&lt;body&gt;&lt;div class="profile">
      &lt;form name="profileForm" id="profileFormId" method="post" action="profile/save/1"&gt;

        <div><span>First Name</span></div>
            &lt;/form&gt;    
</div>
&lt;/body&gt;
    
    [removed][removed]
    &lt;!--[removed][removed]--&gt;
    &lt;!--[removed][removed]--&gt;
&lt;/html&gt;



However fire bug renders this
Code:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
2
3<h4>A PHP Error was encountered</h4>
4
5<p>Severity: Notice</p>
6<p>Message: Undefined index: js</p>
7<p>Filename: controllers/profile.php</p>
8<p>Line Number: 52</p>
9
10</div>&lt;html&gt;
11 &lt;head&gt;
12 &lt;link REL="shortcut icon" HREF="http://localhost/wedding/images/favicon.ico" type="image/x-icon"&gt;&lt;/link>
13 &lt;title&gt;Welcome to Dean &amp; Jessies Wedding Website&lt;/title&gt;
14
15 &lt;link rel="stylesheet" type="text/css" href="http://localhost/wedding/css/global.css" &gt;&lt;/link>
16
17 &lt;!--[if gte IE 5]>
18 &lt;link rel="stylesheet" type="text/css" href="http://localhost/wedding/css/ie-style.css"&gt;&lt;/link>
19 <![endif]--&gt;
20
21 &lt;/head&gt;
22
23&lt;body&gt;&lt;div class="profile">
24 &lt;form name="profileForm" id="profileFormId" method="post" action="profile/save/1"&gt;
25 <div><span><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
26
27<h4>A PHP Error was encountered</h4>
28
29<p>Severity: Notice</p>
30<p>Message: Trying to get property of non-object</p>
31<p>Filename: views/guest_profile_view.php</p>
32<p>Line Number: 3</p>
33
34</div></span></div>
35 &lt;/form&gt;
36</div>
37&lt;/body&gt;
38
39 [removed][removed]
40 &lt;!--[removed][removed]--&gt;
41 &lt;!--[removed][removed]--&gt;
42&lt;/html&gt;

Does any one have a clue as to why this is happening?????

Thanks!
#2

[eluser]TheFuzzy0ne[/eluser]
What's line number 3 of ./system/application/views/guest_profile_view.php?
#3

[eluser]ericsodt[/eluser]
Code:
<div><span>&lt;?=$guest->f_name?&gt;</span></div>
#4

[eluser]Dam1an[/eluser]
So obviously the $guest object isn't being created properly, can you show the code leading up to it, where you create it etc

(if you do print_r on the guest, you should get nothing?
#5

[eluser]ericsodt[/eluser]
[quote author="Dam1an" date="1245457350"]So obviously the $guest object isn't being created properly, can you show the code leading up to it, where you create it etc

(if you do print_r on the guest, you should get nothing?[/quote]

Not the case Sad This is what I get when I do
Code:
print_r($guest)
on the view

Code:
stdClass Object ( [id] => 1 [f_name] => FirstName [l_name] => LastName [food] => stdClass Object ( [id] => 1 [type] => Steak [desc] => Filet with a creme butter sauce ) [attending] => 1 [couple_id] => 1 [hasGuest] => 0 [isRegistered] => 0 [address] => My Road [city] => Fairfax [state] => MA [zip] => 99999 ) 1

however jquery throws this same error and firebug see's the page rendered as
Code:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined index: js</p>
<p>Filename: controllers/profile.php</p>
<p>Line Number: 52</p>

</div>&lt;html&gt;
&lt;head&gt;

&lt;title&gt;Welcome to Dean &amp; Jessies Wedding Website&lt;/title&gt;

&lt;link rel="stylesheet" type="text/css" href="http://localhost/wedding/css/global.css" &gt;&lt;/link>

&lt;/head&gt;

&lt;body&gt;1<div class="profile">
&lt;form name="profileForm" id="profileFormId" method="post" action="profile/save/1"&gt;
<div><span><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Trying to get property of non-object</p>
<p>Filename: views/guest_profile_view.php</p>
<p>Line Number: 6</p>

</div></span></div>
&lt;/form&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;

&lt;!-- JS HERE --&gt;
[removed][removed]
&lt;!--[removed][removed]--&gt;
&lt;!--[removed][removed]--&gt;
#6

[eluser]ericsodt[/eluser]
[quote author="Dam1an" date="1245457350"]So obviously the $guest object isn't being created properly, can you show the code leading up to it, where you create it etc

(if you do print_r on the guest, you should get nothing?[/quote]

Ok, leading up to the view, this is the Controller and how the controller handles the info
Code:
function guest($guestId){
        $couples = $this->session->userdata('coupleData');
        //var_dump($couples);
        $guestObj = $couples[$guestId];
        //var_dump($guestObj);
        $allFood = $this->Food->getAllFood();
        //var_dump($allFood);
        $data = array(
                    'title' => 'Site Title',
                    'content' => 'guest_profile_view',
                    'module' => 'profile',
                    'guest' => $guestObj,
                    'foods' => $allFood
               );
        $this->load->view('layout/template/siteLayout',$data);        
    }
#7

[eluser]srisa[/eluser]
Line no. 52 in controllers/profile.php, what does it look like?
#8

[eluser]ericsodt[/eluser]
[quote author="srisa" date="1245458482"]Line no. 52 in controllers/profile.php, what does it look like?[/quote]

Code:
47      // couple data is stored in the session as an array of Guest Objects.  I index
48      // into that array to pull out the Guest Object I want
49    function guest($guestId){
50        $couples = $this->session->userdata('coupleData');
51        //var_dump($couples);
52        $guestObj = $couples[$guestId];
53        //var_dump($guestObj);
54        $allFood = $this->Food->getAllFood();
55        //var_dump($allFood);
56        $data = array(
57               'title' => 'Website Title',
58               'content' => 'guest_profile_view',
59               'module' => 'profile',
60               'guest' => $guestObj,
61               'foods' => $allFood
62        );
63        $this->load->view('layout/template/siteLayout',$data);        
64    }
#9

[eluser]ericsodt[/eluser]
[quote author="srisa" date="1245458482"]Line no. 52 in controllers/profile.php, what does it look like?[/quote]

The view see's it as an Object as well...
Code:
&lt;?
    //echo print_r($guest);
    //reset($guest);
    echo is_object($guest);
?&gt;
<div class="profile">
      &lt;form name="profileForm" id="profileFormId" method="post" action="profile/save/1"&gt;
        <div><span>&lt;?=$guest->f_name?&gt;</span></div>
        &lt;/form&gt;
</div>

prints out 1 (True) Why would jquery be causing this. As soon as I remove jquery from my footer, firebug doesnt report an error
#10

[eluser]srisa[/eluser]
echo out the $guestId in the guest() function. Also, you need to serialize objects before storing them in sessions, i don't think you can store them as is.




Theme © iAndrew 2016 - Forum software by © MyBB