how to edit clistview and cgridview with bootstrap3 - php

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.

Related

Is it possible to use custom view script in forms on Zend Framework 2?

Is there a way to use a custom phtml view on Zend Framework 2?
In ZF1, I've used something like this:
$form->setDecorators(array(array(
'viewScript',
array(
'viewScript' => 'persons/custom-form.phtml',
array('formId' => 'persons-form')
))));
Here's my ZF1 sample custom-form.phtml:
<form id="<?php echo $formId ?>">
<?php echo $this->element->id; ?>
<?php echo $this->element->name; ?>
</form>
Yes, although, form decorators were removed from ZF1 to ZF2. Now, to render your form with a custom partial, render that partial in your view templates just as you would any other partial and pass your form object as a view variable.
<?= $this->partial('your-partial', array('form' => $form)) ?>
You could work with this in your controller's action
$result = new ViewModel();
$result->setTemplate('somemodule/somecontroller/somescript.pthml')
return $result;

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 do I add an ID to a label tag in Zend Framework 1.9?

This:
$promo_details = new Zend_Form_Element_Textarea('promo_details');
$promo_details->setLabel('Promo Details: ')
->setDecorators($element_decorators)
->addDecorator('Label', array('tag' => 'div'));
outputs:
<div id="promo_details-label">
<label for="promo_details" class="optional">Promo Details:</label>
</div>
but I want to output:
<div id="label_row"> <-- changed the div#
<label for="promo_details" class="optional">Promo Details:</label>
</div>
How do I tell Zend to not use the default ID it generates for "addDecorator('Label', array('tag' => 'div'))" but instead allow me to specify my own? I can't find any information pointing me in the right direction.
#Royal BG ----
If I do:
->addDecorator('Label', array('tag' => 'div', 'class' => 'label_row'))
I get:
<div id="promo_details-label">
<label for="promo_details" class="label_row optional">Promo Details:</label>
</div>
Where the class is added to the label instead of the div tag around the label, which is where I want it to go.
There is no way to set id for the label decorator's tag (see Zend_Form_Decorator_Label render() - the id is hardcoded there as label id + "-label").
To get html you want you can either:
Override Zend_Form_Decorator_Label and provide sort of setTagId() there - certainly an overkill
Use Zend_Form_Decorator_Label without tag option, and wrap it with Zend_Form_Decorator_HtmlTag (with id needed) manually
Disable element's decorators at all and render with custom view script

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
}

how to decorate a zend navigation menu?

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?

Categories