Remove 'home' link from breadcrumb - php

I have breadcrumbs such as Home > Instance > Action in all my view pages. How can I remove the 'Home' link from all the breadcrumbs?
$this->breadcrumbs=array(
'Keypairs'=>array('admin'),
'Manage',
);

This can be done by setting the homeLink property to false, in your CBreadcrumbs widget initialization. This is usually done in a layout file.
In the default Yii app, in protected/views/layouts/main.php:
<?php if(isset($this->breadcrumbs)):?>
<?php $this->widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
'homeLink'=>false // add this line
)); ?><!-- breadcrumbs -->
<?php endif?>

in layouts/main.php add 'homeLink' => false
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs'])? $this->params['breadcrumbs'] : [],
'homeLink' => false
]) ?>

Related

Customizing the Templates FormHelper for just plugins CakePHP 3?

I would like to customize a form helper template for just a plugin, not across the App.
Example: 'inputContainer' => '<div class="form-control">{{content}}</div>',
How do I go about doing this in CakePHP 3?
As per the docs - to change theme inline at runtime use setTemplate:
$myTemplates = [
'inputContainer' => '<div class="form-control">{{content}}</div>',
];
?>
<?= $this->Form->create('Users') ?>
<? $this->Form->setTemplates($myTemplates); ?>
<?=
$this->Form->input('email', [
'class' => 'form-control',
'templates' => [
'formGroup' => '{{input}}{{label}}'
]])
?>
You can't use the templates option on the Form for a dynamic template, it will only look for a config file listing template items in /config.

How to change default layout for ALL controllers in Yii2?

How do I change the default layout globally (= for all controllers and views) in Yii2? I want to leave the main.php layout as is in case I want to use it later.
In root of configuration you can write default layout [[\yii\base\Application::$layout]] for all views:
[
...
'layout' => 'main',
'components' => [
...
]
]
Configure layout & layoutPath in Yii2 config:
$config = [
...
'layoutPath' => '#app/views/layouts2',
'layout' => 'main2.php',
];
Above example changes default view app/views/layouts/main.php to app/views/layouts2/main2.php.
Yii2 Application Structure > Application
You can do in the following way. For example a defaultLayout.php layout can be created like this:
<?php $this->beginContent('#app/views/layouts/main.php'); ?>
<div class="container">
<div class="row">
<div class="col-lg-4">Left Side Bar</div>
<div id="content" class="col-lg-4">
<?php echo $content; ?>
</div><!-- content -->
<div class="col-lg-4">Right Side Bar</div>
</div>
</div>
<?php $this->endContent(); ?>
Inside the relative action
public function actionIndex()
{
$this->layout = 'defaultLayout';
return $this->render('index', [
'model' =>$model,
]);
}
In configuration(config/main.php) you can overwrite the default layout for all your views
[
// ...
'components' => [
'view' => [
'layout' => 'main.php'
],
// ...
],
]
In your config, you can edit the layoutPath .
Example:
$config = [
...
'layoutPath' => '#app/views/layouts-2'
];
Change in config/web.php file
and add this line before components array
your new style name which is created in view/layout/main_style.php
'layout' => 'main_style'
Using this whole project layout changed

Custom CLinkPager Yii Framework

basically:
<?php $this->widget('CLinkPager', array(
'pages' => $pages,
)) ?>
when render: 'Go to page:...'
i want to push 'Go to page: ' to my element (ext: Go to page), somebody can help me?
If I am not wrong you might want to access the header property of CLinker page which defaults to Go to page
<?php $this->widget('CLinkPager', array(
'pages' => $pages,
'header'=> 'whatever you want'
)) ?>

how to pass a php variabe to yiibooster modal window via link

I want to pass a php variable to modal window , what i am doing is opening a modal window using this link , but i want to pass a variable to this link and get same variable in modal window , i try to to do this to append a text in some div but it return html that i am unable to get in query
echo CHtml::link(
'Set Recipe', '', array(
'class' => 'testclass',
'id' => $finalDate,
'data-toggle' => 'modal',
'data-target' => '#myModal',
'fahadVar' => $finalDate
));
and when i click this button i got modal window how to get variable set in button
Here is simple modal code of yiibooster
<div class="modal-body">
<p>One fine body...</p>
</div>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'type' => 'primary',
'label' => 'Save changes',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Close',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
thanks in advance
You should create a Widget.
Note: I copied below from another post. It works like charm.
First Create a new widget. Let say the name is CategoryWidget. Put this widget under components directory protected/components.
class CategoryWidget extends CWidget {
public function run() {
$models = Category::model()->findAll();
$this->render('category', array(
'models'=>$models
));
}
}
Then create a view for this widget. The file name is category.php. Put it under protected/components/views
category.php
<?php if($models != null): ?>
<ul>
<?php foreach($models as $model): ?>
<li><?php echo $model->name; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Then call this widget from your main layout.
main.php
// your code ...
<?php $this->widget('CategoryWidget') ?>

FancyBox like in gii module

I want a FancyBox like that one in the gii module code generator. I have downloaded the EFancyBox extension and made it run. The first time when i press the link the fancybox is properly displayed and i close it, but when i try the second time a blank window appears with no content. Here is the code:
<?php echo CHtml::link($url,"#data", array('id'=>'iframe')); ?>
<div style="display:none">
<div id="data"><iframe src="<?php echo $url; ?>"
frameborder=0 width=1024 height=768 scrolling=yes></iframe></div> </div>
<?php $this->widget('application.extensions.fancybox.EFancyBox',
array( 'target'=>'a#iframe', 'config'=>array( 'scrolling' => 'no', 'titleShow' => true, ), ) ); ?>
</div>
I have found the solution:
<?php $this->widget('application.extensions.fancybox.EFancyBox', array( 'target'=>'a#iframe', 'config'=>array( 'scrolling' => 'no', 'titleShow' => true, 'onClosed'=>"js:function(){parent.location.reload(true);}" ), ) ); ?>
It seems ok to me, because when you reload the data you need to tell to the fancybox the new dom elements, when you reload you tell the new elements, its ok like that.
<?php $this->widget('application.extensions.fancybox.EFancyBox', array( 'target'=>'a#iframe', 'config'=>array( 'scrolling' => 'no', 'titleShow' => true, 'onClosed'=>"js:function(){parent.location.reload(true);}" ), ) ); ?>

Categories