how to decorate a zend navigation menu? - php

i have this menu:
$menu['talent'] = array(
array('id' => 'welcome',
'label' => 'My Profile',
'uri' => '/profile/,
'class' => 'navlink'
)
),
array('id' => 'welcome',
'label' => 'My Profile',
'class' => 'navlink',
'uri' => '/profile/
),
);
this will end up looking like this:
<ul>
<li>My Profile</li>
<li>My Profile</li>
<ul>
how can i change the ul into a div and also the li into something else?
any idas?
Thanks

Well, to accomplish this I would use one of these two methods:
Using a View Helper and overload menu()
In order to overload Zend_View_Helper_Navigation_Menu, you could write you own helper, register it and make it extends Zend_View_Helper_Navigation_Menu. In your helper, you can overload the method you want such as _renderMenu() and make it renders <p> instead of <li> for example. In your View Helper, you would have to return the parent::menu() or something like this.
Finally, you have to register this new View Helper using:
$view->addHelperPath(APPLICATION_ROOT . '/library/My/View/Helper/Navigation', 'My_View_Helper_');
Using a partial script
This one seems to me a little bit longer, but it worth a try.
Basically, you need to set a partial script to your navigation using setPartial() method and you menu will be rendered through this partial.
<?= $this->navigation()->menu()->setMaxDepth(2)->setPartial('partials/_nav.phtml')->render() . PHP_EOL; ?>
Afterwards, in your _nav.phtml you can render your menu as you wish. From this partial, you can access the menu variables using $this->container. Then, you can iterate through each page of your container, and display what you want.
I know all of this seem pretty complicate for such a simple task, but unfortunately this is the only solution. Does anyone have a better idea?

Related

How to use html edit character (✎) instead of directly use "edit" in cakephp?

i have this link
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $o->id]) ?>.
Instead of Edit ,i want to use edit html character (✎).
please help.
Use this code
✎
instead of Edit text
will produce ✎ icon
Just add "escape" parameter and set it to false.
You may wanna refer to this: CakePHP 3 creating links
<?php
echo Html->link(__('✎'),
['action' => 'edit', $o->id],
['escape' => false]
) ?>

Yii 2 Exclude NavBar in Modal

In my index.php view, I have a button, once clicked, a modal will pop up:
<p>
<?= Html::button(
'Create New BizAdmin',
['value' => Url::to(['createbizadmin']),
'class' => 'btn btn-success',
'id' => 'modalButton'
]) ?>
<?php
Modal::begin(['id' => 'modal']);
echo "<div id='modalContent'></div>";
Modal::end();
?>
</p>
My modal file is createbizadmin.php where it has the following codes:
<?php
use yii\helpers\Html;
/* #var $this yii\web\View */
/* #var $model app\models\User */
$this->title = 'Create New Bizadmin';
?>
<div class="user-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_formbizadmin', [
'model1' => $model1,
'model2' => $model2,
]) ?>
</div>
My problem is this:
As you can see, the navbar looks horrible. The menu list seems to overflow outside the modal.
How do I get rid of the navbar inside my modal? I can't seem to find which part of creatbizadmin.php I should edit.
Any thoughts?
I'm guessing that you have a controller somewhere that is handling the url createbizadmin. I'm also guessing that inside that controller action you are rendering the view file like this;
$this->render("createbizadmin");
If so, then that is your problem. By calling a view file directly, Yii will apply default layouts to the view file. You have no control over how this happens from within the called view file, and all your menus etc will be rendered.
To get around this you will probably need to render a partial file. This rendres the file without applying layouts. So use;
$this->renderPartial("createbizadmin")
Alternatively, if the modal content is being generated as a result of an ajax call, you can respond from the controller with;
$this->renderAjax("createbizadmin")
This article seems to have a good explanation of how best to achieve this; Render a form in a modal popup

how to edit clistview and cgridview with bootstrap3

I like to use bootstrap 3 with yii. I am stuck with how to edit CListview and CGridview and add in the neccesarry classes.
My code
$this->widget('zii.widgets.CListView',array(
'dataProvider'=>$dataProvider,
// refers to the partial view named '_thumb'
'itemView'=>'_thumb',
'template' => "{summary}{sorter}{pager}{items}{pager}",
'itemsCssClass' => 'nav row',
'pagerCssClass'=>'pagination', // doesn't work is set on <div> instead of <ul>
// 'sorterCssClass'=>'row-fluid', // how to so this...
)); ?>
I tried putting the 'pagination' class. but the class is splaced on the div tag instead of the ul tag that is required. With CGridview it is the same
I used the yii bootstrap extension but it doesn't work with bootstrap3 and I like to know how to do it the easy way.

how to add HTML CMenu in yii

Hope you are all doing well. I have been trying to implement CMenu in Yii template. I am using,
$this->widget('zii.widgets.CMenu', array(
'items'=>$this->menu,
'htmlOptions'=>array('class'=>'collapse','id'=>'component-nav'),
));
And I want to dislpay my HTML output as
<li class=""><i class="icon-angle-right"></i> List Registration </li>
But I can not insert this section: <i class="icon-angle-right"></i> beside the label i.e. "List Registration". Is there any way to insert this <i class="icon-angle-right"></i> html part beside every label of item.
Please help me someone.
Thanks in advance
A quick dirty way:
$this->menu = array_map(function($item){
$item["label"] = "<i class='icon-angle-right'></i>" . $item["label"];
$item["encodeLabel"] = false;
return $item;
}, $this->menu);
$this->widget('zii.widgets.CMenu', array(
'items'=>$this->menu,
'htmlOptions'=>array('class'=>'collapse','id'=>'component-nav'),
));
Information from http://www.yiiframework.com/wiki/525/customizing-the-cmenu-widget/
Disable HTML encoding 'encodeLabel' => false,
Submenu change class 'submenuHtmlOptions' => array('class' => 'dropdown-menu',)
Use label property
'label' => '<i class="icon-user"></i><span class="username">Admin</span> <i class="icon-angle-down"></i>', Very useful with bootstrap
Use YII url property for correct adress i.e. 'url' => array('site/logout'),
I don't think Yii provides a way to add a html element inside a according to the class reference (yiiframework.com/doc/api/1.1/CMenu). If you want to do it the css way:
#component-nav li a {
background: url('path/to/image.png') no-repeat;
padding-left: 30px; // depends of the width of your image
}

Passing default data for a controller in Laravel

I want to build a menu from an array in Laravel. What I'm currently doing is putting the array in a view
$menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];
and then looping through it to generate the menu:
<section>
<!-- Left Nav Section -->
<ul class="left">
<li class="divider"></li>
#foreach($menu as $key => $nav)
<li class="has-dropdown">
{{ $key }}
<ul class="dropdown">
#foreach($nav as $subnav)
<li>
{{ $subnav }}
</li>
#endforeach
</ul>
</li>
#endforeach
</ul>
</section>
Is there any other way that I can achieve the same result without putting the data in the view?
I also tried creating a constructor function in the controller:
public function __construct() {
$menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];
return $menu;
}
But I guess that is not how it works. I appreciate any ideas on how I can go about this. Thanks in advance
View composers to the rescue!
They are executed every time before a view is rendered, so you can use this to pass standard data to them.
If you're using controller layouts you can bind data to the layout from within the constructor. Just make sure you call the parent constructor first so that the layout is instantiated properly.
public function __construct()
{
parent::__construct();
$this->layout->menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];
}
That will bind a $menu variable to the layout, and will also be available to any nested views that are used with Blades #include.
Have a look at view composers:
http://www.laravel.com/docs/views#view-composers

Categories