Every page a random picture with ipSlot - impresspages

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.

Related

Yii how to highlight the current label

$this->breadcrumbs=array(
'Dailymarket Reports',
);
$this->menu=array(
array('label'=>'inbox', 'url'=>array('index')),
array('label'=>'sent', 'url'=>array('sent')),
);
Above I have two labels. I want inbox to be default active label if mouse moves out and selects sent as active it should be highlighted.
I think you are asking about how to show the menu item selected according to the current route if you are on Home page then the Home menu item should be selected.
Although you can see solutions like adding checks but if you provide full path to your link you won't have to add any further checks for activating the menu items, just make sure you are not passing activateItems=>false inside the CMenu widget in the layout file, otherwise it defaults to true and it decides whether to automatically activate items according to whether their route setting matches the currently requested route.
Go to your view where you are adding the menu specify a full path like /controller/action for your links for example if I have a menu for the site controller SiteController actions I will provide paths like below.
$this->menu=array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Demo', 'url'=>array('/site/demo')),
);
and that's it you can make it work if you don't need to add separate checks for every menu item.
Just make sure you have a css class for li.active > a so that you can get the highlighted effect,
If you want to add active class for specified items:
$this->menu = array(
array(
'label' => 'inbox', 'url' => array('index'),
'active' => $this->action->id === 'index' ? true : null,
),
array(
'label' => 'sent', 'url' => array('sent'),
'active' => $this->action->id === 'sent' ? true : null,
),
);
You need to style items with active class yourself.
You may also omit specifying url for current item, so it will be displayed as text instead of link:
$this->menu = array(
array(
'label' => 'inbox',
'url' => $this->action->id === 'index' ? null : array('index'),
),
array(
'label' => 'sent',
'url' => $this->action->id === 'sent' ? null : array('sent'),
),
);

how to pass the id of the click CButtonColumn of CGridView going to the controller in Yii1.x?

I have a custom CButtonColumn within the CGridView.
one of the custom buttons is firing a CJuiDialog. now the problem is,
how to pass the id when clicked, so that the Controller will get the id, then I can do pass a model and renderPartial it inside the CJuiDialog?
here's what i have so far
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->controller->createUrl("mycontrollerName/view,array("id" => "$data->id"))',
'click' => "function( e ){
e.preventDefault();
$( '#view-dialog' ).data('id',$(this).attr('id'))
.dialog( { title: 'View Details' } )
.dialog( 'open' ); }"
),
having given that code snippet.. in the controller action, I want to have the id ..is it $_GET['id'] ?, or $_POST['id'] ?..it doesn't matter for as long as I can get it so that I can use it to query in the model function
There are a few syntax errors in your code, but more importantly, you shouldn't wrap $data->id in any quotes.
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->createUrl("mycontrollerName/view", array("id" => $data->id))',
'click' => "function( e ){
e.preventDefault();
$( '#view-dialog' ).data('id',$(this).attr('id'))
.dialog( { title: 'View Details' } )
.dialog( 'open' ); }",
),
So you are trying to pass the id value in the javascript code.
This is more of a jQuery issue rather than having much to do with Yii.
Run console.log($(this).attr('id')); you will probably see that you get an 'undefined' value. That is because the tag generated by Yii for the button does not contain an id parameter.
The easiest solution is to use jQuery to work with the url parameter.
e.g.
$( '#view-dialog' ).data('id',$(this).attr('href'))
if the entire URL is not needed, you could use a regex to parse only the numerical ID.
Alternatively you will have to pass the id in the buttons option parameter.
e.g.
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->createUrl("mycontrollerName/view", array("id" => $data->id))',
'options' => array('id' => $data->id),
'click' => "function( e ){
...
However, please note that Yii will not render the value of $data->id in the 'option' parameter as this is not evaluated in CButtonColumn.
You will have to override Yii's CButtonColumn (see http://www.yiiframework.com/wiki/372/cbuttoncolumn-use-special-variable-data-for-the-id-in-the-options-of-a-button/)
Personally, if I were you, I'd implement some Javascript in some external code and have a regex to parse the id from the URL.

Yii widgets.TbThumbnails Pagination

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',
)
);
?>

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.