Multi navigation failed in layout - zend-framework2

why second var_dump() display null in this code in my layout.phtml :
var_dump(($this->navigation('navigation')->menu()->render()));
var_dump(($this->navigation('navigation')->breadcrumbs()->render()));
output :
string '<ul class="navigation">
<li>
DashBoard
</li>
<li>
Members Management
</li>
<li class="active">
Events
<ul>
<li>
Categories
</li>
<li class="active">
Show All
</li>
<li class="active">
<a href='... (length=802)
string '' (length=0)
EDIT :
actually changing var_dump order ... OMG ... again the second one is NULL !! :-O
Output :
string 'Events > Show All' (length=51)
string '' (length=0)

There was a bug in zf2 ver <= 2.1.3 about this and its closed but not yet merged into production package and will be fixed in next minor release
https://github.com/zendframework/zf2/issues/3976
Simple solution :
https://github.com/froschdesign/zf2/commit/454439d35716ed2125a6ac90c826836f57391eb0

the contents on breadcrumbs will depends where the output is executed.
for example, if you are inside a controller and action which has been assigned to one of your navigation items, then it should be picked up.
I suspect you haven't setup navigation pages for the controller/action pairing where you are performing the var_dump.
Example nav config:
array(
'navigation' => array(
'default' => array(
array(
'label' => 'Page One',
'route' => 'myroute',
'controller' => 'categories',
'action' => 'list',
),
If you perform your output in the listAction method of your Categories controller then the breadcrumb helper should return something for you

Related

Using ZfcUser and BjyAuthorize to show or hide views

I have recently installed ZfcUser and BjyAuthorize and would like to use them to show or hide various parts of the layout.phtml file.
I understand that BjyAuthorize is a firewall of sorts and the flowchart from git hub suggests it should be possible to get current permission status and to use that to hide or show a particular section of code.
So for instance:
<ul>
<li>Admin Menu item</li>
<li>Affiliate menu item</li>
<li>Guest Menu item</li>
</ul>
If an admin user is logged in, he will view all three items, the affiliate will only see Affiliate and guest and the guest will only see guest.
How I was thinking of doing this was something like this:
<?php
//Get array of permissions for current user *not certain how to do this*
$permissionArray = $this->GetBjyPermissions($current->user);
?>
<ul>
<?php if in_array('admin',$permissionArray) {?>
<li>Admin Menu item</li>
<?php } ?>
<?php if in_array('affiliate',$permissionArray) {?>
<li>Affiliate Menu item</li>
<?php } ?>
<li>Guest Menu item</li>
</ul>
Essentially this will allow me to hide the sections of code a user is not allowed to use.
If it is not possible to get the permissions via Bjy or Zfc I guess my option would be to simply query the Database and build a permissions array from that directly.
Has anyone else had to do something like this? Is this approach a good approach or is there another way of achieving this?
Many thanks for any input.
You can use the BjyAuthorize's IsAllowed view Helper. It knows the current user's identity, so you just have to check the rule. It works like:
$isMenuAdmin = $this->isAllowed( 'menu', 'menu_admin' );
$isMenuAffiliate = $this->isAllowed( 'menu', 'menu_affiliate' );
$isMenuGuest = $this->isAllowed( 'menu', 'menu_guest' );
menu is a resource and menu_* a rule. You have to define them in the bjyauthorize.global.php. I'd do it this way:
(...)
'resource_providers' => array(
'BjyAuthorize\Provider\Resource\Config' => array(
'menu' => array(),
),
),
'rule_providers' => array(
'BjyAuthorize\Provider\Rule\Config' => array(
'allow' => array(
/*
[0] -> role
[1] -> resource
[2] -> rule
*/
array( array( 'admin' ), 'menu', array( 'menu_admin' ) ),
array( array( 'affiliate' ), 'menu', array( 'menu_affiliate' ) ),
array( array( 'guest' ), 'menu', array( 'menu_guest' ) ),
),
),
),
(...)
BTW, it seems that you're trying to build a menu. I recommend you to check this post about integrating Zend Navigation with BjyAutorize.

how can i make cucumber test on multiple 'a' tag with image

this is my view code where i have make multiple 'a' tag and want to test third element from li. and we can uniquely identified with offer id as per below code ...
<div class="search_data_outer_div">
<ul>
<li class="small_preview">
<div class="image_area">
<a href="/offer/show/334">
</div>
<span>
<span class="artist_name">Artist 1</span>
<span class="remaining_time">Remaining Time: 7 days</span>
<i id="334" class="icon-remove pointer" style="position:absolute;right:0;display:none;"></i>
</span>
</li>
and i have tried make one step defination ... it is working fine with cucumber but when execute with selenium (WebDriver) then page not open after click.
Scenario:
When I press third offer
Then I should see "YOUR OFFER"
and its step defination file
When /^I press third offer$/ do
page.execute_script %Q{ $(".search_data_outer_div ul li .image_area a").eq(2).click(); }
end
let me know right solution if anybody can help
thanks
IIRC CSS style selectors have issues with some version of Web Driver. Ideally you'd have PageObject variables set up for this so you're not using raw webdriver code in your steps but something like this should work:
browser.div( :class => 'search_data_outer_div').div( :class => 'image_area').links.first.click

How to adapt this wordpress loop query code to include pagination?

I have sourced the below code to query my posts in Wordpress and all works as intended.
I'd like to add pagination to this now. I don't want to alter the code too much now that I know it works, can anyone advise on the best way to adapt this to include the pagination?
I would like it to show a maximum of 18 posts per page and have next and prev links to other pages if they exist. This code is being used in custom category templates, but I have also setup a static page setup under the reading settings and the display of main posts uses home.php, I'd like to use the same or similar loop code to also paginate that. Any help is appreciated. Here is the code:
<div id="Items">
<ul>
<?php
// Grid sorted alphabetically
if (is_category('categoryName'))
{
$args = array( 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'category' => 41 );
$categoryNameposts = get_posts( $args );
}
foreach( $categoryNameposts as $post ) : setup_postdata($post);
?>
<li><?php get_template_part( 'content', get_post_format() ); ?></li>
<?php endforeach; ?>
</ul>
</div><!-- #ItemsEnd -->
You should let wordpress know how much post you want to show per page in the query_posts. Replace your $args with these two lines:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'posts_per_page' => 18, 'paged' => $paged, 'orderby'=> 'title', 'order' => 'ASC', 'category' => 41 );
Now to show Next-Previous link:
<div class="paginationClass">
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
</div>
Also in is_category function, use categorySlug, instead of categoryName.

Model#id returns #object_id in haml views

I'm having a weird error in my haml views. When I ask for model.id it returns object_id but only in some places. Example:
%ul
- #items.each do |item|
%li{:class => "item", :id => "item_#{item.id}"}= link_to(item.name,item)
The code above renders this:
<ul>
<li class="item" id="item_104589">Test1</li>
<li class="item" id="item_104590">Test2</li>
</ul>
I said this is a weird error because it's only happening on production environment and links are correct.
The array of items are "decorated" using Drapper gem. I'm not using the short form of haml because of this:
%li[item]
Renders:
<li class="item_decorator" id="item_decorator_xxx">...</li>
thanks to Leonid, I found the problem with ItemDecorator.
ItemDecorator override the method id from class Item:
item = ItemDecorator.decorate(item)
=> #<ItemDecorator:0xcdbcc78 #context={}, ...
irb(main):004:0> item.id
(irb):4: warning: Object#id will be deprecated; use Object#object_id
=> 107865660
I wonder if it is a bug of Drapper or not.

putting jquery buttons in clistview widget in yii

I am trying to put a button which will be displayed along with some data in the view file I specified in "itemView" field of the CListView widget, but instead of the styled button for every list item, I am just getting it or the first list item. My code in the _view file is:
<div id="listView">
<div class="thedata">
...some data
</div>
<div id="buttons">
<?php
$this->widget('zii.widgets.jui.CJuiButton', array(
'buttonType'=>'button',
'name'=>'btnJobs',
'caption'=>'Manage Jobs',
'options'=>array('icons'=>'js:{primary:"ui-icon-wrench"}'),
'onclick'=>'js:function(){alert("Manage Jobs clicked."); this.blur(); return false;}',
));
?>
</div>
</div>
and the code for CListView widget is just the bare minimum:
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view'
));
any suggestions?
Try passing in a unique ID to the CJuiButton, like so:
<?php
$this->widget('zii.widgets.jui.CJuiButton', array(
'id'=>'button'.$data->id, // add a unique ID here (could use $index instead of $data->id)
'buttonType'=>'button',
'name'=>'btnJobs',
'caption'=>'Manage Jobs',
'options'=>array('icons'=>'js:{primary:"ui-icon-wrench"}'),
'onclick'=>'js:function(){alert("Manage Jobs clicked."); this.blur(); return false;}',
));
?>
The problem is that since all of your buttons have the same 'name' (and therefore 'id') jQuery is only binding to the first one. Making sure each button has a unique ID should fix this, so jQuery will bind correctly.

Resources