Yii2: How can I place something into a Breadcrumbs widget? - php

I find the Breadcrumbs widget quite useful. However, on the right side within the widget there is enough space for something else. If I'd like to put a link ('a' tag, but could be actually any other small thing) right aligned into the Breadcrumbs, how could I do that? What is a simple and proper solution? Should I extend the class, develop my own, use begin and end of the widget somehow?

If you look at yii\widgets\Breadcrumbs you see that there is a third parameter in the breadcrumbs items
From the Yii2 file
[
'label' => 'Post Category',
'url' => ['post-category/view', 'id' => 10],
'template' => "<li><b>{link}</b></li>\n", // template for this link only
],
So by adding something like this in your main layout file
$this->params['breadcrumbs'][] = [
'label' => 'Your Label',
'url' => ['controller/action'],
'template' => "<li style="float: right;">{link}</li>\n"
];
you will get a link at the right side. This link will come with a / prefixed, but you can bind it to a .class instead and configure it the way you want.
'template' => "<li class=\"yourClass\">{link}</li>\n"

Related

Change home text and URL in Yii2 Breadcrumbs widget

I want to change default text "Home" and also the URL for home.
While searching on it I found suggestion that need to set homeUrl but I don't have any idea where to set it.
Please ask for code if you need it.
You need to configure $homeLink property:
echo Breadcrumbs::widget([
'homeLink' => [
'label' => 'My name',
'url' => '/my/url',
],
'links' => [
// your items
],
// rest of widget config
]);

How can I put in a proper image path URL for radio button options in my Wordpress Child Theme Customizer?

I've been working on this for a while and even though i've searched through a lot of stackoverflow questions/answers, i haven't been able to find what i'm looking for.
My question:
I'm working on developing my first genesis wordpress child theme, particularly now the customizer. I want the user to be able to have different options, one of which is choosing from a few background patterns that I've designed for a certain div class. There are three different patterns, and I've been able to so far make three radio buttons. Here is the code:
$wp_customize->add_setting('BG_Pattern', array( 'default' => '#f5ebdf',));
$wp_customize->add_control('BG_Pattern', array(
'label' => __('Background Pattern', 'FoxiePro'),
'section' => 'backgrounds',
'settings' => 'BG_Pattern',
'type' => 'radio',
'choices' => array(
'tan.jpg' => 'Tan',
'#e6e6e6' => 'gray',
'teal' => 'teal',
),
));
And the output is this, in the header.php file:
<?php
$BG_Pattern = get_theme_mod('BG_Pattern');
?>
<style>
.enews-widget {background-image: url( '<?php echo $BG_Pattern; ?>' );}
</style>
Where it says "tan.jpg", is where I would like to put in a url to tan.jpg src, which is in my child theme folder. However, any link I put in doesn't make the pattern appear. Inputting something like:
'bloginfo('template_url'); ?>/images/tan.jpg' => 'Tan',
also hasn't worked for me. Anyone have any ideas? Thanks!
Figured it out, because it's a child theme, needed to use the following:
get_stylesheet_directory_uri() . '/images/backgrounds/tan.jpg' => 'Tan',

Yii CGridView customizing column head sort icons and row links

I am dealing with the CGridView widget in Yii. I've customized most of it, but can't seem to customize the icons that appear when you click on the column headers to sort the data. (little arrows that point either up or down depending on the sort order) Also, the icons are completely gone after adding in the 'columns' option. A portion of the code in my view is below:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'pager' => array('cssFile' => '/css/myCss.css'),
'cssFile' => '/css/myCss.css',
'summaryText' => 'Showing {start} - {end} of {count} data rows.',
'htmlOptions' => array('id' => 'grid'),
'columns' => array(
array(
'name' => 'name',
'value' => '$data->name',
),
array(
'name' => 'description',
'value' => '$data->description',
),
array(
'name' => 'date',
'value' => '$data->date',
),
),
));
?>
Yii's documentation isn't clear at all on this and there doesn't seem to be anyone (that I could find) that also has this issue.
->Also, a related question:
How would I make each row an anchor link? I need each row to be a link to view the details about the clicked row. I know that cgridview provides view, edit, and delete links at the end of the row if told to, but is it possible to get the entire row to be a single anchor link? I know how to do this manually in html, but don't know how to do this inside cgridview.
If you want to change the icon in the header of the table, you will need to override styles for classes (.grid-view table.items th a.desc and .grid-view table.items th a.asc). You can also disable visual styles for the table by specifying an option: 'cssFile'=>false and set custom styles for grid.
In order to make the entire string anchor link is likely you will need to insert into each cell of the table with the necessary link url. To do this, add the following description of an array of strings:
'columns'=>array(
...
array(
'name'=>'name',
'value'=>'CHtml::link($data->name, "#myAnchor")',
'type'=>'html'
),
...
)
I am not sure what version of Yii you're working on, but let's try this code
<?php
'columns' => array(
array(
...
'type' => 'html',
'value'=>'CHtml::tag("a",array("class"=>"your-icon-class", "href"=>"#"))',
),

ZF2 Input Filter Change Message Color

I made typical form with ZF2 form and wanted to add validation using ZF2 InputFilter. It was success but the colour of error message is black which is looks strange. I tried to change the colour by using method I've searched like this:
array(
'name' =>'NotEmpty',
'options' => array(
'messages' => array(
NotEmpty::IS_EMPTY => '<div style="color:red;">Please enter User Name!</div>'
),
),
),
But, instead of message's colour changed to red, it showed the tag with style, in other word, just plain HTML. What is the proper way to achieve my need?
Easiest way would be to modify the view helper ;)
Inside your module.config.php
'view_helpers' => [
'factories' => [
'formelementerrors' => function($vhm) {
$fee = new \Zend\Form\View\Helper\FormElementErrors();
$fee->setAttributes([
'class' => 'your error classes'
]);
return $fee;
}
]
]
The alternate approach when rendering errors using $this->formElementErrors() would be to add the error classes inside the ViewHelper directly
$this->formElementErrors($element, ['class' => 'my error classes']);

Yii insert html in custom CListView

My problem: the two pagination options are on separate lines.
I have:
<div class="search_result searchconright">
<?php
$this->widget('zii.widgets.CListView', array(
'id' => 'listViewSearch',
'dataProvider' => $model->search(),
'itemView' => '_index_post',
'enablePagination' => true,
'pager' => array(
'cssFile' => Yii::app()->baseUrl . '/css/clistview.css',
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',
),
'summaryText' => '',
'sortableAttributes' => array(
),
));
?>
</div>
<div class="pagetxt">
<span>View</span>
<a class="page_search_limit">All</a>
<a class="page_search_limit page_search_limit_active">3</a>
<a class="page_search_limit page_search_limit_active">5</a>
<a class="page_search_limit page_search_limit_active">24</a>
<a class="page_search_limit">48</a>
</div>
and i would like to insert the entire html from class pagetxt in the widget, because the seccond pagination, is under the widgets pagination; i would like them to be on the same line
also, other suggestions are welcomed
the pagination:
You have 2 options, first the way you are doing it, you can use the template property of CListView, to add the HTML where you want inside the widget.
But It looks like what you are trying to do, is to allow the user to specify the number of elements they want to see per page, so I'd recommend to use something like the PageSize extension
I think you can do this with CSS:
.search_result, .pagetxt {
display: inline-block;
}
To change the CListView pagination HTML, you would have to create a new CLinkPager and the pass parameters to it. So I think CSS is way simpler :)
This is purely a layout issue: you need to have the pager render inline with your custom HTML.
One way to do that would be to give display: line-block to both of these DIVs with CSS, but of course you can also use other techniques like floating.
You can easily target the stock pager by setting the pagerCssClass property on your list view; the default is simply "pager", so you could do
$this->widget('zii.widgets.CListView', array(
'id' => 'listViewSearch',
'pagerCssClass' => 'pager pager-inline'
// ...
);
and then for example
.pager.pager-inline, .pagetxt {
display: inline-block;
}

Categories