Yii widgets.TbThumbnails Pagination - yii

I am using this 'widgets.TbThumbnails' from bootstrap to show the list of items as thumbnails. It shows first 10 items in one page and another 10 items on the other page. further it shows page navigator button at the bottom of the page. I tried to show all the items in a single page, but couldn't. If anyone know please help me to fix this. here is my code for thumbnail view
<?php $dataProvider = new CActiveDataProvider('Symptoms');
$this->widget('ext.bootstrap.widgets.TbThumbnails',
array(
'dataProvider' => $dataProvider,
//'template' => "{items}\n{pager}",
'itemView' => '_thumb',
//'htmlOptions' => array('style' => 'width:975px;','height:1020px'),
)
);
?>

Well that is due to the fact that dataProvider uses default settings for pagination.
Cpagination has a property named pageSize which refers to the the number of items per page. By default this is set to 10 thats why you can see 10 items per page.
Here is Official documentation.
You can do like this:
<?php
$dataProvider = new CActiveDataProvider('Symptoms', array(
'pagination'=>false
));
$this->widget('ext.bootstrap.widgets.TbThumbnails', array(
'dataProvider' => $dataProvider,
'itemView' => '_thumb',
)
);
?>

Related

yii1 GridView Pagination not updating Grid when changing Page

I am still very new to yii1 and fight now with a GridView. I have build a Search Form and when sending of the form, the page gets re-loaded and the GridView shows up with the results. The form goes to the Controller action and gets the appropriate records That works well, besides Pagination is not working. As soon I click on the next page, the GridView is empty, if I refresh the Page, the GridView shows the results for that page and moved on in my Pagination Link. What am I doing wrong here? I have printed out the $dataProvider in my view and it seems to hold all the data, but the table shows no records. Any hint what I am doing wrong? I really hope someone can help. Thank you so much !
myController.php
$dataProvider = new GridDataProvider('MyModel', array(
'criteria'=>$criteria,
));
$this->render('overallSearch',
array(
'model'=>$model,
'dataProvider'=>$dataProvider,
));
myView.php
$this->widget('zii.widgets.grid.CGridView', array(
'id' =>'search-grid-new',
'emptyText' => 'No records found',
'htmlOptions' => array('class'=>'grid-view search-grid'),
'dataProvider'=> $dataProvider,
'ajaxUpdate' => true,
'columns' => $columns,
));
UPDATE
I actually thought that the problem is solved, but for some reason it is not and I am sure that I should not have to save the result in a Session anyway. Anyone any idea what I am doing wrong?

Every page a random picture with ipSlot

I have a problem. Every page gets the same header image. I use following code:
<?php
$options = array('id' => 'Image', 'width' => '500', 'class' => 'cssclass(optional)');
echo ipSlot('image', $options);
?>
I would like to choose a![enter image description here][1] random image on each page without using blocks.
Thanks!
Add current page id as an image ID and you will have separate image for each page. Eg.:
$options = array('id' => 'Image' . ipContent()->getCurrentPage()->getId(), 'width' => '500', 'class' => 'cssclass(optional)');
echo ipSlot('image', $options);
When you select an image, there's "Apply to" filter below it. Choose "Current page and all subpages" and you'll get what you want. No need to hack through page IDs. Unless you want that.

how to edit pagination behaviour in yii

hello i am creating a search module which is taking data from apis..
Now i am getting all result in 1 api call and i am making it as a dataProvider.
this is the code..
$dataProvider = new CArrayDataProvider($result, array(
'sort' => array(
'attributes' => array('name',
),
),
'pagination' => array(
'pageSize' => 10,
),
));
this is working fine and giving pagination. What i want to do is to use limit and ofset of api.
for eg consider the yelp api
http://api.yelp.com/search?term="xxx"&location="xxx"&limit=10&ofset=0;
i want to get only 10 result initially and i need another api call to get next set when i click the pagination [2] or next >.
how can this be done ?
I also need a expert opinion. which one is better.? calling api at single time and fetch all detail once or getting few one by one ? the expected results will be around 200..
Yelp doesn't allow to "cache" its search results in any meaning http://www.yelp.com/developers/getting_started/api_terms (section 6). So I believe you need to do call each time pagination link is clicked.
For this purpose I would create some YelpDataProvider extended from CDataProvider and override required abstract methods.
Pagination:
Not sure I got what kind of problem you faced with, but if you implement your own data provider you will have access to CPagination class instance and its properties pageSize and offset.
pageSize is to be mapped to limit yelp request parameter, offset property - directly to offset request param.
I hope this will help.
http://www.yiiframework.com/doc/api/1.1/CPagination
$dataProvider = new CArrayDataProvider($result, array(
'sort' => array(
'attributes' => array('name'),
),
'pagination' => array(
'pageSize' => 10,
'offset' => 5
),
));

yii CListView is not updating when we delete the records through ajax request

here i am using the ajax request to delete the record from the clistview the record is deleting succesfully but the list view is not updating if we refresh the page then only the record is removing from the clist view can any one help here is my code
<?php
echo CHtml::link(CHtml::encode('Delete'), $this->createUrl('delete', array('id' => $data['id'])), array(// for htmlOptions
'onclick' => ' {' . CHtml::ajax(array(
'type'=>'POST',
'beforeSend' => 'js:function(){if(confirm("Are you sure you want to delete?"))return true;else return false;}',
'url'=>$this->createUrl('delete', array('id' => $data['id'],'ajax'=>'delete')),
'complete'=>'js:function(jqXHR, textStatus){$.fn.yiiListView.update("firstlist");}'
)) .
'return false;}', // returning false prevents the default navigation to another url on a new page
)
);
here is the code for clistview
<?php $this->widget('zii.widgets.CListView', array(
'id' => 'firstlist',
'dataProvider'=>$dataProvider,
'itemView'=>'_beneview',
'enablePagination' => false,
'summaryText' => '',
)); ?>
You could use CHtml::ajaxLink for ajax request, but your way is also fine.
I have filtered CListView results also with paginations enabled, you can just look at the major things for updating list view on this link
Please check view part and updating script part.
Hope his will help.
Use CGridView, you can add CButtonColumn

Yii - Design question - Keeping dialoges separate from the main view file and accessing them

I have a case where on my view file there are 6 links and clicking on them opens CJuiDialog boxes . I am keeping all the 6 dialog boxes code in the same view file along with links and that is causing the file to be big and loading them all together once .The ideal scenario is the dialog boxes should get loaded only when the use clicks on the links .
So is there any way we can keep only the links code in the main view file and keeping all the dialogue boxes in separate files and loading them only when the user clicks on the links
I mean
index.php ( view containing only links)
_dialog1 ( containing code for first dialog )
_dialog2 ( containing code for second dialog )
_dialog3 ( containing code for third dialog )
_dialog4 ( containing code for fourth dialog )
_dialog5 ( containing code for fifth dialog )
_dialog6 ( containing code for sixth dialog )
Sample Code
//First Dialog code
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog1',
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>false,
'modal'=>true,
),
));
echo 'First dialog content here';
$this->endWidget('zii.widgets.jui.CJuiDialog');
echo CHtml::link('open dialog', '#', array(
'onclick'=>'$("#mydialog1").dialog("open"); return false;',
));
//2nd dialog code
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog2',
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>false,
'modal'=>true,
),
));
echo 'dialog2 content here';
$this->endWidget('zii.widgets.jui.CJuiDialog');
echo CHtml::link('open dialog', '#', array(
'onclick'=>'$("#mydialog2").dialog("open"); return false;',
));
Solution I came with
//In controller
public function actionOpenDialog1()
{
$data = array();
$this->renderPartial('_dialogContent1', $data, false, true);
}
public function actionOpenDialog2()
{
$data = array();
$this->renderPartial('_dialogContent2', $data, false, true);
}
//In index.view
<div id="data">
</div>
<?php
echo CHtml::ajaxButton ("Open first dialog", CController::createUrl('dialogTesting/openDialog1'),array('update' => '#data'));
echo CHtml::ajaxButton ("Open second dialog", CController::createUrl('dialogTesting/openDialog2'),array('update' => '#data'));
?>
//_dialogContent1.php
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog1',
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>true,
'modal'=>true,
),
));
echo 'first dialog content here';
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
//_dialogContent2.php
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog1',
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>true,
'modal'=>true,
),
));
echo 'first dialog content here';
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
Thanks a lot for your help
Regards
Kiran
Naming files
The convention in Yii is to name the view files:
index.php: a full view
_dialog1.php: a partial view (included from another view)
Sub views
Then you can include partial views with CController::renderPartial():
$this->beginWidget(...);
$this->renderPartial('_dialog1', array('var1' => 23, 'var2' => "var"));
$this->endWidget(...);
Factorizing code
This should make your source node much lighter. But I suggest you go farther and avoid duplicating all those widget calls. To do this, you should define a structure for your dialog parameters and loop over it. Something like:
$dialogs = array(
'mydialog1' => array(
'file' => '_dialog1',
'options' => array('title' => "My title 1",),
),
'mydialog2' => array(
'file' => '_dialog12,
'options' => array('title' => "My title 2",),
),
);
$defaultOptions = array(
'autoOpen' => false,
'modal' => true,
);
foreach ($dialogs as $id => $dialog) {
$this->beginWidget(
'zii.widgets.jui.CJuiDialog',
array(
'id' => $id,
'options' => CMap::mergeArray($defaultOptions, $dialog['options']),
)
);
// ... include partial view ...
This factorization will make your code more compact, but it will above simplify the future changes. Using data structures to avoid code duplication is a well-known practice.
AJAX
Lastly, if you really want the partial views to be loaded dynamically, that means you have to use AJAX. Be careful, because your page may be less reactive from a user point of view. If all your forms amount to a few Kb of HTML, then there's no nedd for AJAX. But if you go this way, then you'll need to:
Add an CJuiDialog containing just <div id="dialog-ajax"></div>.
Create another action that will apply renderPartial() on the dialog views.
Replace the content of the previous foreach loop with code that writes JS like function dialog1() {jQuery("#dialog-ajax").load(...);}. You'll need to hack if you want to change dynamically the widget title.
Bind some events (clicks) to these JS functions.
Another way would be to make your aJAX action render a full CJuiDialog, it might be simpler and avoid JS hacks. Anyway, I'm not sure you really need AJAX.
My answer
//In controller
public function actionOpenDialog1()
{
$data = array();
$this->renderPartial('_dialogContent1', $data, false, true);
}
public function actionOpenDialog2()
{
$data = array();
$this->renderPartial('_dialogContent2', $data, false, true);
}
//In index.view
'#data'));
echo CHtml::ajaxButton ("Open second dialog", CController::createUrl('dialogTesting/openDialog2'),array('update' => '#data'));
?>
//_dialogContent1.php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog1',
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>true,
'modal'=>true,
),
));
echo 'first dialog content here';
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
//_dialogContent2.php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog1',
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>true,
'modal'=>true,
),
));
echo 'first dialog content here';
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
You can simply include one empty CJuiDialog in your page, and when it needs to be displayed load the contents with jQuery AJAX (load is the simplest, and probably enough) that returns a render of the appropriate view before opening the dialog.