cerberus478 Posted October 11, 2011 Share Posted October 11, 2011 Hi I know my title doesn't give any information but I really have no idea what my problem is. The problem I have is that for some reason my code just stopped working, it was working fine in the beginning and then all of a sudden I'm getting undifined index: item, and I'm not sure what it was that I did wrong since it was working fine in the beginning. Can someone please help because this has me confused Thank you Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/ Share on other sites More sharing options...
codefossa Posted October 11, 2011 Share Posted October 11, 2011 Code? Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278039 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 This is the listings.php <script type="text/javascript" charset="utf-8"> var selected_vid = <?php echo $this->_params['item']['id'] ?>; $(document).ready(function() { $("#main_vid_embed_code > object > embed").each(function(index, domEle){ $(this).attr('width', '401'); $(this).attr('height', '243'); }); }); changeVideo=function(video_id){ if(video_id == selected_vid){ return; } //$("#video_"+video_id).css('background-color', '#DFE6E4'); //$("#video_"+selected_vid).css('background-color', '#FFFFFF'); $("#video_"+video_id).removeClass('vid-entry').addClass('vid-entry-active'); $("#video_"+selected_vid).removeClass('vid-entry-active').addClass('vid-entry'); selected_vid = video_id; var url="/videos/ajax_get/"; $.post(url, {'video_id': video_id, 'format': 'JSON' }, function(data){ var JSONString = '{"video": '+data+'}'; data = JSON.parse(JSONString); $("#main_vid_title").html('<h2>'+data['video']['name']+'</h2>'); $("#main_vid_description").html(data['video']['description']); $("#youtube").html(data['video']['embed_code']); $("#comments_list").empty(); for(i=0;i<data['video']['comments'].length; i++){ if(data['video']['comments'][i]['email']){ $("#comments_list").append('<strong><a href="mailto:'+data['video']['comments'][i]['email']+'">'+data['video']['comments'][i]['name']+'</a> - '+data['video']['comments'][i]['date']+':</strong> <br />'+data['video']['comments'][i]['description']+'<div class="line"></div>'); }else{ $("#comments_list").append('<strong>'+data['video']['comments'][i]['name']+' - '+data['video']['comments'][i]['date']+':</strong> <br />'+data['video']['comments'][i]['description']+'<div class="line"></div>'); } } $("#youtube > object > embed").each(function(index, domEle){ $(this).attr('width', '450'); $(this).attr('height', '270'); }); }); } addComment=function(){ var url="/comments/ajax_add/"; $.post(url, {'video_id': selected_vid, 'name': $("#comment_name").val(), 'description': $("#comment_description").val(), 'email': $("#comment_email").val(), 'format': 'JSON' }, function(data){ var JSONString = '{"comment": '+data+'}'; data = JSON.parse(JSONString); if(data['comment']['id']){ if(data['comment']['email']){ $("#comments_list").prepend('<strong><a href="mailto:'+data['comment']['email']+'">'+data['comment']['name']+'</a> - '+data['comment']['date']+':</strong> <br />'+data['comment']['description']+'<div class="line"></div>'); }else{ $("#comments_list").prepend('<strong>'+data['comment']['name']+' - '+data['comment']['date']+':</strong> <br />'+data['comment']['description']+'<div class="line"></div>'); } $("#comment_name").val('Name'); $("#comment_description").val(''); $("#comment_email").val('Email'); $("#comment_name_error").html(''); $("#comment_email_error").html(''); $("#comment_description_error").html(''); $("#comments").attr('scrollTop', '0'); }else{ if(data['comment']['errors']['name']){ $("#comment_name_error").html('Please enter your name'); } if(data['comment']['errors']['email']){ $("#comment_email_error").html('Please enter a valid email address'); } if(data['comment']['errors']['description']){ $("#comment_description_error").html('Please enter a comment'); } scrollBottom(); } }); } function scrollBottom(){ $('#comments').animate({scrollTop: $('#comments')[0].scrollHeight}); } </script> <div class="top-head-1st"> <h1>Video Directory</h1> </div> <div class="top-head-2nd"> <h2>Q&A sessions with industry leaders</h2> </div> <div id="v-left"> <?php $videos_model = new videos_model('videos'); $videos = $videos_model -> get_all(); foreach($videos as $video){ ?> <div id="video_<?php echo $video['id'] ?>" <?php if($video['id'] == $this->_params['item']['id']){?>class="vid-entry-active"<?php }else{?>class="vid-entry"<?php }?>> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td valign="top" width="3%"><img src="/image.php?path=<?php echo $video['image_path']?>&w=120&h=90" width="120" height="90" /></td> <td valign="top" width="97%"><div class="vid-info"> <strong><?php echo $video['name']?></strong><br /> <?php echo $video['length']?> | Added <?php echo date('d / m / Y', $video['created']) ?><br /> <div style="padding-top: 11px;"><a href="javascript:;" onclick="changeVideo(<?php echo $video['id'] ?>);"> Watch Video</a></div> </div></td> </tr> </tbody> </table> </div> <?php }?> </div> <div id="v-right"> <div class="content"> <div id="main_vid_title"> <h2><?php echo $this->_params['item']['name'] ?></h2> </div> <div id="youtube" class="youtube"> <?php $this->display_youtube($this->_params['item']['embed_code'], 443, 270); ?> </div> <div id="main_vid_description" class="info"><?php echo $this->_params['item']['description'] ?></div> <h2 style="margin-top:15px;">Comments</h2> <div style="clear:both;"></div> <div class="comments" id="comments"> <?php if(!empty($this->_params['item']['comments'])) {?> <div id="comments_list"> <?php foreach($this->_params['item']['comments'] as $comment){ ?> <strong><?php echo $comment['name'] ?> - <?php echo date('d / m / Y', $comment['created']) ?>:</strong> <br /> <?php echo $comment['description']?> <div class="line"></div> <?php } ?> </div> <?php }?> <div class="leave-comment"> <h2 style="padding-top: 8px;">Leave a comment</h2> <table width="100%" border="0" cellpadding="2" cellspacing="0"> <tbody> <tr> <td><div id="comment_name_error"></div> <input name="comment_name" class="name" id="comment_name" onfocus="if (value='Name') {value=''}" onblur="if (value=='') {value='Name'}" value="Name" size="33" type="text" /> * <div id="comment_email_error"></div> <input name="comment_email" class="name" id="comment_email" onfocus="if (value='Email') {value=''}" onblur="if (value=='') {value='Email'}" value="Email" size="33" type="text" /> * (Will not be made public)</td> </tr> <tr> <td><textarea id="comment_description" name="textfield" cols="50" rows="6">Message </textarea> <br /> <br /> <input class="submit" value="Submit" onclick="addComment();" type="submit" /></td> </tr> </tbody> </table> </div> <br /> <br /> <div id="small-banner" style="margin-left:15px;"><img src="/img/fractionalownership/sponsor.png" width="164" height="15" /><br /> <?php echo $this->display_banner('bottom');?></div> </div> </div> </div> and this is the videos.controller.php <?php class videos_controller extends controller{ protected $_helpers = array('form', 'html'); protected $_observers = array('seo_uris'); public $model='videos'; public function ajax_get(){ $video_id = register('video_id'); $video = $this->_model->get($video_id); if(!empty($video['comments'])){ $comments = $video['comments']; $video['comments'] = array(); foreach ($comments as $comment){ $comment['date'] = date('d / m / Y', $comment['created']); $video['comments'][] = $comment; } } $this->_params['item'] = $video; $this->_view = 'index'; } public function listings($id = false){ $videos = $this->_model->get_all(); foreach($videos as $video){ $sql = "SELECT 1 FROM videos, pages, pages_videos WHERE videos.id = pages_videos.video_id AND pages.id = pages_videos.page_id AND pages.name = 'Video Directory'"; if(empty($video['image_path']) || !$this->_model->get_one($sql)){ continue; } $this->_params['list'][] = $video; } if(!empty($id)){ $this->_params['item'] = $this->_model->get($id); }elseif(isset($this->_params['list'][0])){ $this->_params['item'] = $this->_model->get($this->_params['list'][0]['id']); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278040 Share on other sites More sharing options...
codefossa Posted October 11, 2011 Share Posted October 11, 2011 Right away I see your semicolon outside of the PHP tags. If that don't fix it, then you'll have to wait on someone else 'cause I'm off to bed. Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278042 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 nope it didn't work Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278045 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 This line var selected_vid = <?php echo $this->_params['item']['id'] ?>; should be var selected_vid = <?php echo $this->_params['item']['id']; ?>; That is assuming that $this->_params['item']['id'] is not a string. When you say you are getting "undefined index" which line does that relate to in the code you have posted.. Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278059 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 It's in listings.php <div id="main_vid_title"> <h2><?php echo $this->_params['item']['name'] ?></h2> </div> <div id="youtube" class="youtube"> <?php $this->display_youtube($this->_params['item']['embed_code'], 443, 270); ?> </div> <div id="main_vid_description" class="info"><?php echo $this->_params['item']['description'] ?></div> It's these lines Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278060 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 The error is not occurring on this line? var selected_vid = <?php echo $this->_params['item']['id']; ?>; Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278066 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 the web page doesn't give me any errors on that line Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278068 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 Do a var_dump($this); before and after the $videos_model = new videos_model('videos'); $videos = $videos_model -> get_all(); I am guessing that the code above is somehow responsible. Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278070 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 turn error reporting on. <?php // error reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> did you get any errors? Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278074 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 He has already stated that he has received errors. Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278077 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 he should post the whole error code so we would know where the problem lies in. Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278079 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 11, 2011 Share Posted October 11, 2011 <div id="main_vid_title"> <h2><?php echo $this->_params['item']['name'] ?></h2> </div> <div id="youtube" class="youtube"> <?php //arent you suppose to echo the line below? echo $this->display_youtube($this->_params['item']['embed_code'], 443, 270); ?> </div> <div id="main_vid_description" class="info"><?php echo $this->_params['item']['description'] ?></div> arent you suppose to echo that line? Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278081 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 Buddski I did what you ask and it gave me a huge thing. Where would I look. I wanted to show you but it tells me that I exceeded the maximum allowed length Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278090 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 Sorry, maybe just do var_dump($this->_params); Should give you less output. Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278092 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 This is what the var_dump($this->_params) showed me: array(1) { ["site"]=> array(3) { ["id"]=> string(1) "4" ["name"]=> string(10) "HighLiving" ["industries"]=> array(3) { [29]=> array(4) { ["id"]=> string(2) "29" ["name"]=> string(3) "Spa" ["created"]=> string(10) "1317997663" ["modified"]=> string(10) "1317997663" } [30]=> array(4) { ["id"]=> string(2) "30" ["name"]=> string(7) "Message" ["created"]=> string(10) "1317997868" ["modified"]=> string(10) "1317997868" } [31]=> array(4) { ["id"]=> string(2) "31" ["name"]=> string(5) "Sniff" ["created"]=> string(10) "1317997935" ["modified"]=> string(10) "1317997935" } } } } Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278098 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 Is that before or after $videos_model = new videos_model('videos'); $videos = $videos_model -> get_all(); Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278102 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 before $videos_model = new videos_model('videos'); $videos = $videos_model -> get_all(); I also tried print_r($this->_params['item']['embed_code']); and it gave me null. Which I found strange because it was working fine yesterday afternoon Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278106 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 It looks like, from the array of params you posted, that item isnt being defined as an index of that array, which asks the question, why did it not error on the first line?! You will have go look deeper into your classes and find where _params is being set, and go from there. Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278116 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 I have _params['item'] in majority of my classes. In my video_controller class the $this->_params['item'] = $video these are the other _params in the video_controller class if(!empty($id)){ $this->_params['item'] = $this->_model->get($id); }elseif(isset($this->_params['list'][0])){ $this->_params['item'] = $this->_model->get($this->_params['list'][0]['id']); } Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278122 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 Is listing.php just a normal (not inside a class) PHP page that calls the videos_model? Edit: no that cant be right, because var_dump($this) displayed results.. Which class are you using to call/load/include listing.php Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278123 Share on other sites More sharing options...
cerberus478 Posted October 11, 2011 Author Share Posted October 11, 2011 yep listings.php is the view side Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278124 Share on other sites More sharing options...
cerberus478 Posted October 12, 2011 Author Share Posted October 12, 2011 Buddski just letting you know I found the problem and it was the most idiotic thing ever on my part. But thanks for helping Quote Link to comment https://forums.phpfreaks.com/topic/248873-no-idea-what-the-problem-is/#findComment-1278511 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.