Jump to content

No idea what the problem is


cerberus478

Recommended Posts

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

Link to comment
Share on other sites

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']);
	}

}

}
?>

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<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?

Link to comment
Share on other sites

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" } } } }

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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']);
	}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.