Load More Ajax

Hello everyone,

I’m newbie in yii, and right now i’m stuck on this problem.

I want to create load more comments based on ajax like facebook/twitter, could u please recommend good extension or give me simple example how the code works with yii.

Please someone help me,

Thanks before…

Hi, check this out :

http://www.yiiframework.com/extension/yiinfinite-scroll/

Hi,

Welcome to Yii Community.

So, for your problem there is nothing to do with Yii here. You must be clear with the logic behind this. Then just implement it in Yii.

You can refer the example code from below given link.

Link1

Link2

Thanks for your reply Mirunho,

i’ve already tried infinite scroll extension, but it’s only works on 1 post perpage, instead i’ve used clistview inside clistview.

Maybe you know how to make it works on me please.

Thanks codesutra, i’ve been tried from native php and it works, but when i tried to yii it always failed.

Could u please tell me how to implented this native php script on yii.

here is the script.

$per_page=8;

if(isset($_POST[‘pageLimit’]) && !empty($_POST[‘pageLimit’])){

$pageLimit=$_POST['pageLimit'];

}else{

$pageLimit='0';

}

$pageLimit=$pageLimit;

$query="select * from tbl_replypost order by id_rep desc

    limit $pageLimit,".$per_page;

$res=mysql_query($query);

$count=mysql_num_rows($res);

$HTML=’’;

if($count > 0){

while($row=mysql_fetch_array($res)){

   $post=$row['notes'];


   $link=$row['notes'];


   $HTML.='<div>';


   $HTML.='<a href="'.$link.'" target="blank">'.$post.'</a>';


   $HTML.='</div><br/>';


}

$loadCount=$pageLimit+$per_page;

if($count >= $per_page){

   $HTML.='<div class="load_more_link">';


   $HTML.='<input type="button" class="button" value="Load More" 


   onclick=loadData("'.$loadCount.'")>';


   $HTML.='<span class="flash"></span></div>';

}

}else{

   $HTML='No Data Found';

}

echo $HTML;

Well for better implementation of this code you can simply debug the code written in the extension suggested by mirunho. Since this is the same thing you are looking for.Only thing is that if there is some other requirements with this then you have to modified that extension.

But Logically if you want to implement that jquery plugins in yii then simple create one controller action which will load the data same it is written in PHP script.And for that you can get some idea from that extension

Any how you have to some debugging in it.So, you will find the solution.

Also i can not understand exactly here what you mean by




i've already tried infinite scroll extension, but it's only works on 1 post perpage, instead i've used clistview inside clistview.



Can you please explain it a bit more.

Also,

That is a code which is loading data for next pages.So, you have to check how they are loading data with this Jquery. or simply what code is written in this Widget.


 public function actionIndex()

    {

            $criteria = new CDbCriteria;

            $total = Post::model()->count();

 

            $pages = new CPagination($total);

            $pages->pageSize = 20;

            $pages->applyLimit($criteria);

 

            $posts = Post::model()->findAll($criteria);

 

        $this->render('index', array(

                'posts' => $posts,

                'pages' => $pages,

            ));

    }




Widget Code. 


$this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array(

    'itemSelector' => 'div.post',

    'pages' => $pages,

));



Dear codesutra,

i’ve been tried it and its works perfectly but it doesn’t have the trigger button, now the only i need is the trigger button to load more the content. Could you show me how to make the trigger button with this extension please.

When you will see the demo example given on the extension page you will see that.

There is a link in bottom of the page. With text "NEXT".




<div class="infinite_navigation" style="display: none;"><a href="/demos/yiinfinite_scroll/index?page=2">next</a></div>



personally i haven’t tested that extension.But still i will say you need to dig more into the widget code.So, you can get better idea.

Anyways can you please share your current code for this functionality.

This is a code for that. on this page.I think something what you need to test.

Hi all,

I’m really newbie for yii. I’ve tried for the “Load More” function.

My problem is, I use this function works in one template, but not with this template.

The problem template is, load from ajax function that appear the list after filtering, then using the same ajax load more code with another template, it’s really makes me confuse, it didn’t works.

Please help me, why is this happen. Here’s my example code :

<div class="showing-box">

&lt;?php


&#036;limit = (&#036;total_data &lt; 10 ) ? &#036;total_data : 10; 			


&#036;number_more = (&#036;total_data - &#036;limit &lt; 10) ? &#036;total_data - &#036;limit : 10;


?&gt;


&lt;span&gt;&lt;?php echo Yii::t('Mine', 'SHOWING'); ?&gt; &lt;span class=&quot;offset&quot;&gt;&lt;?php echo(&#036;limit); ?&gt;&lt;/span&gt; &lt;?php echo Yii::t('Mine', 'OF'); ?&gt; &lt;?php echo &#036;total_lender; ?&gt; &lt;?php echo Yii::t('Mine', 'USERS'); ?&gt;&lt;/span&gt;


&lt;?php if (&#036;limit &#33;= &#036;total_data) { ?&gt;


&lt;strong&gt;					


&lt;?php


   echo CHtml::ajaxLink(


       Yii::t('Mine', 'LOAD').' &lt;span class=&quot;number_more&quot;&gt;'.&#036;number_more.'&lt;/span&gt; '.Yii::t('Mine', 'MORE'),								 


           Yii::app()-&gt;createAbsoluteUrl('site/UserListAjax'),


	array(


	     'type' =&gt; 'POST',


	     'data' =&gt; array(


	     'offset' =&gt; 'js:&#036;(&quot;span.offset&quot;).html()',


	     'nocheckbox' =&gt; 'true',


	     'filter' =&gt; &#036;filter


	),


	'success' =&gt; &quot;function(data) {									


	&#036;('div.item-list').append(data);


	var new_offset = parseInt(&#036;('span.offset').html()) + 10;


	if (new_offset &gt;= &#036;total_lender) {


		&#036;('.showing-box').remove();


	} else {


	&#036;('span.offset').html(new_offset);


	if (&#036;total_lender - new_offset &lt; 10)


		&#036;('span.number_more').html(&#036;total_lender - new_offset);


	}


	}&quot;


	)


	);


?&gt;					


&lt;/strong&gt;


&lt;?php } ?&gt;

</div>

hi sutra,

I tried click on the “Next” link, it is not showing more ‘comments’, but it looks like loaded next page of ‘comments’.

How to make it load the ‘next page comments’ in the same page at the bottom of the last previous page comments ?

Thank you.