So i have a Zend_Route in my application like this :
public function _initRoutes() {
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route(':language/:controller/:action/*',
array(
'language' => 'de',
'controller'=> 'index',
'action' => 'index'
),
array(
'language' => '[a-z]{2}'
));
$router->addRoute('lang_route', $route);
}
and my xml
<?xml version="1.0" encoding="UTF-8" ?>
<configdate>
<nav>
<home>
<label>Home</label>
<controller>index</controller>
<action>index</action>
<pages>
<my_account>
<label>Galery</label>
<controller>index</controller>
<action>list</action>
</my_account>
</pages>
</home>
<login>
<label>Login</label>
<controller>login</controller>
<action>index</action>
</login>
</nav>
</configdate>
My problem is, that Zend_Navigation creats wrong urls.
So when i enter the url
http://localhost/zf/public/en
the urls generated by Zend_Navigation still looks like
http://localhost/zf/public/de/index/
Hope anyone has some ideas :)
You have to add the route you want to use for creating the correct URL in your Xml configuration:
<?xml version="1.0" encoding="UTF-8" ?>
<configdate>
<nav>
<home>
<label>Home</label>
<controller>index</controller>
<action>index</action>
<route>lang_route</route>
</home>
</nav>
</configdate>
In the Xml configuration you can use the same keywords as specified for Zend_Navigation_Page_Mvc.
Related
I want to display top rated products in magento 2
My block Toprated.php
public function getTesting()
{
$collection = $this->_productCollectionFactory->create();
foreach($collection as $eachColl)
{
$storeId = $eachColl->getStore()->getId();
$reviewSum = $this->reviewSummaryFactory->create()->setStoreId($storeId)->load($eachColl->getId());
$rated[] = array(
'rating' => $reviewSum['rating_summary'],
'name' => $eachColl->getName(),
'url' => $eachColl->getUrlPath(),
'product_sku' => $eachColl->getSku()
);
$rateds[$eachColl->getSku()] = $reviewSum['rating_summary'];
}
arsort($rateds);
$rateds = array_slice($rateds, 0, 3);
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToFilter('status', '1');
$collection->addAttributeToFilter('rating', array('in' => implode(",", $rateds)));
return $collection;
}
my template toprated.phtml file
<?php
$_productCollection = $this->getTesting();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
?>
but phtml file not calling any data.what i did mistake here
Where do you want to show the new block ?
It is possible by edit/add a layout file in view/frontend/layout/
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="content">
<block
template="[your template]"
class="[your class]"
name="[your name]"/>
</referenceContainer>
create layout file in view -> frontend -> templates -> layout ,
file name should be your routname_controllernamespace_controllername (controller->Index->index.php)
ex. blog_index_index file should be look like this
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Demo\Blog\Block\PostList" name="demo.list" template="Demo_Blog::list.phtml" />
</referenceContainer>
</body>
</page>
This is my navigation XML format, there are 2 user levels in the system, Admin and Super Admin,
When login as Admin all the menu items should be displayed and it works fine, for Super Admin only the Dashboard and statistics should be displayed.
My issue is, for Super admin, along with the dashboard and statistics, labels of the other menu items (those should be displayed only for admin) are showing , Is there any work around to hide the labels. in my case , there are no actions for the top level menu items, except dashboard.
Menu is connected with Zend ACL
<configdata>
<nav>
<dashboard>
<label>Dashboard</label>
<class>nav-top-item no-submenu</class>
<controller>index</controller>
<action>index</action>
<resource>index</resource>
<privilege>index</privilege>
</dashboard>
<app>
<label>Apps</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
<pages>
<managefeaturedapps>
<label>Manage Apps</label>
<controller>app</controller>
<action>index</action>
<resource>app</resource>
<privilege>index</privilege>
</managefeaturedapps>
<managepage>
<label>Filter Apps</label>
<controller>app</controller>
<action>filter-apps</action>
<resource>app</resource>
<privilege>filter-apps</privilege>
</managepage>
</pages>
</app>
<user>
<label>Users</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
<pages>
<allusers>
<label>Registered Users / Developers</label>
<controller>user</controller>
<action>index</action>
<resource>user</resource>
<privilege>index</privilege>
</allusers>
</pages>
</user>
<page>
<label>Pages</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
<pages>
<addpage>
<label>Add New Page</label>
<controller>page</controller>
<action>add-page</action>
<resource>page</resource>
<privilege>add-page</privilege>
</addpage>
</pages>
</page>
<statistics>
<label>Statistics</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
<pages>
<viewstats>
<label>Statistics</label>
<controller>statistic</controller>
<action>index</action>
<resource>statistic</resource>
<privilege>index</privilege>
</viewstats>
</pages>
</statistics>
</nav>
ACL Code
class XXX_Controller_Action_Helper_AclPbo {
public $acl;
//Instatntiate Zend ACL
public function __construct()
{
$this->acl = new Zend_Acl();
}
//Set User Rolse
public function setRoles()
{
$this->acl->addRole(new Zend_Acl_Role('superAdmin'));
$this->acl->addRole(new Zend_Acl_Role('admin'));
}
//Set Resources - controller, models, etc...
public function setResources()
{
$this->acl->add(new Zend_Acl_Resource('app'));
$this->acl->add(new Zend_Acl_Resource('index'));
$this->acl->add(new Zend_Acl_Resource('user'));
$this->acl->add(new Zend_Acl_Resource('page'));
$this->acl->add(new Zend_Acl_Resource('statistic'));
}
//Set privileges
public function setPrivilages()
{
$this->acl->allow('superAdmin', 'user', array('login','logout'));
$this->acl->allow('superAdmin', 'index', 'index');
$this->acl->allow('superAdmin', 'app', 'index');
$this->acl->allow('superAdmin', 'statistic', array('index'));
$this->acl->allow('admin', 'user', array('index','login','logout'));
$this->acl->allow('admin', 'index', 'index');
$this->acl->allow('admin', 'app', array('index'));
$this->acl->allow('admin', 'page', array('index', 'add-page', 'edit-page'));
$this->acl->allow('admin', 'statistic', array('index'));
}
//Set ACL to registry - store ACL object in the registry
public function setAcl()
{
Zend_Registry::set('acl', $this->acl);
}
}
The reason why you are experiencing this behavior lies here
<statistics>
<label>Statistics</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
while you should be having
<statistics>
<label>Statistics</label>
<class>nav-top-item no-submenu</class>
<controller>statistic</controller>
<action>index</action>
<resource>statistic</resource>
<privilege>index</privilege>
As long as you do not define resource's access parameters it is available to anyone.
hi i want to use a breadcrumb for my zend framework application
i craeted navigation.xml in configs folder where application.ini is .
and in the bootstarp i added following code
protected function _initNavigation()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
}
and in the layout i added folllowing code
<div id="menu">
<?php echo $this->navigation()->menu(); ?>
</div>
<div id="breadcrumbs">
You are in: <?php echo $this->navigation()->breadcrumbs()->setLinkLast(false)->setMinDepth(0)->render(); ?>
</div>
it is not working , errors are given
Fatal error: Uncaught exception 'Zend_Navigation_Exception' with message 'Invalid argument: Unable to determine class to instantiate' in /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Page.php:223
Stack trace:
#0 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Container.php(117): Zend_Navigation_Page::factory(Array)
#1 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Container.php(164): Zend_Navigation_Container->addPage(Array)
#2 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation.php(46): Zend_Navigation_Container->addPages(Object(Zend_Config_Xml))
#3 /home/kanishka/workspace/jetwing_ibe/application/Bootstrap.php(94): Zend_Navigation->__construct(Object(Zend_Config_Xml))
#4 /home/kanishka/workspace/jetwing_ibe/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initNavigation()
#5 /home/kanishka/workspace/jetwing_ibe/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('navigati in /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Page.php on line 223
this is my xml file
<?xml version="1.0" encoding="UTF-8"?>
<config>
<nav>
<dashboard>
<label>dashboard</label>
<controller>dashboard</controller>
<action>index</action>
<resource>dashboard</resource>
<pages>
<rates>
<label>Rates</label>
<controller>rates</controller>
<action>index</action>
<pages>
<index>
<label>index</label>
<controller>rates</controller>
<action>index</action>
<class>dontdisplay</class>
</index>
</pages>
</rates>
<occupancydenomination>
<label>Occupancydenominations</label>
<controller>occupancydenomination</controller>
<action>index</action>
<pages>
<index>
<label>Occupancydenomination</label>
<controller>occupancydenomination</controller>
<action>index</action>
<class>dontdisplay</class>
</index>
<add>
<label>Add Occupancydenomination</label>
<controller>occupancydenomination</controller>
<action>add</action>
<class>dontdisplay</class>
</add>
</pages>
</occupancydenomination>
</pages>
</dashboard>
</nav>
</config>
i am not sure what the error is . please help me ................
The error is due to your config file.
You're not providing enough parameters for the navigation container to determine the correct page type, Zend_Navigation_Page_Mvc or Zend_Navigation_Page_Uri.
Also, you know there's a navigation resource plugin, right?
UPDATE
Get rid of the <nav> wrapper element. It's trying to interpret that as a page.
That or do follow the example and specify the config section correctly
$config = new Zend_Config_Xml('/path/to/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
I have configured my zend navigation menu like
Config: http://pastebin.com/B212uWKz
public function _initNavigation() {
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($config);
$this->bootstrap('view');
$view = $this->getResource('view');
$view->navigation($navigation);
}
Layout
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Zend Navigation Test</title>
</head>
<body>
<?php echo $this->navigation()->menu(); ?>
<hr />
<?php echo $this->navigation()->breadcrumbs(); ?>
<hr />
<?php echo $this->layout()->content; ?>
</body>
</html>
The menu works but not the breadbrumbs. I also tried from here
<?php echo $this->navigation()->breadcrumbs()
->setLinkLast(false)
->setMinDepth(0)
->render(); ?>
Still only the menu works
Maybe they use different containers?
Maybe max depth?
<?php echo $this->navigation()->breadcrumbs()
->setLinkLast(false)
->setMinDepth(0)
->setMaxDepth(500)
->render($this->navigation()->getContainer()); ?>
Looking at your code I think that the problem might be because you use uri tags rather then controller and action tags. For instance instead of:
<home>
<label>Home</label>
<uri>/</uri>
</home>
there should be:
<home>
<label>Home</label>
<controller>index</controller>
<action>index</action>
</home>
Hope it will work for you.
I have the following problem, using zend framework, specifically zend_nav to create a reusable menu to be passed in via the layout/layout.phtml page. These are the code fragments in their respective files.
first of in application/configs/navigation.xml,
<configdata>
<nav>
<label>Home</label>
<controller>index</controller>
<action>index</action>
<pages>
<add>
<label>Add</label>
<controller>post</controller>
<action>add</action>
</add>
<login>
<label>Admin</label>
<controller>login</controller>
<action>login</action>
</login>
</pages>
</nav>
</configdata>
this is then passed into an object in the Bootstrap.php file(only showing that specific method)
protected function __initNavigation(){
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
$view->navigation($container);
}
and then finally in the view layout.phtml, the object should return the menu
<!-- application/layouts/scripts/layout.phtml -->
<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Zend Blog !</title>
<?php echo $this->headLink()->appendStylesheet('/css/global.css')?>
</head>
<body>
<div id="header">
<div id="header-logo">
<b>Blog Me !</b>
</div>
</div>
<div id="menu">
<?php echo $this->navigation()->menu() ?>
</div>
<div id="content">
<?php echo $this->layout()->content ?>
</div>
</body>
</html>
The menu does however not show up when i start up my app in the browser, any ideas as to might have gone wrong, is humbly received.
If you did not name the function __initNavigation with two _ underscores on purpose then you probably expected the code to run automatically. For it to run automatically you need to use a single underscore.
Another possible problem is that _initNavigation runs before _initView as Zend goes through these resources in alphabetical order. But then you need not access $view in this code. You can use the Zend_Registry to store the navigation container:
protected function _initNavigation() {
$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
Zend_Registry::set('Zend_Navigation', $container);
}
The Zend_Navigation registry entry will be used by default by any navigation helper when no container is specified.
Well i`m impressed, really quick answers, the problem had several aspects, first of you where both right about using a single underscore sign, thanks a lot the both of you !
And as i t turned out, i did misspell,
$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
should be,
$config = new Zend_Config_Xml(APPLICATION_PATH .'/configs/navigation.xml', 'nav');
my fault. And finally a miss in the navigation.xml file, inside the - node, there should be nodes surrounding each of the "page" nodes, that is for instance for the home. It should have
<configdata>
<nav>
<home>
<label>Home</label>
<controller>index</controller>
<action>index</action>
</home>
That was it !
Again, thanks a lot for your hints and tips i the right direction.
Sinc Kalle Johansson
I think your code is correct, just your protected function __initNavigation()
should use just one _ in your _initNavigation()
Then change __initNavigation() to _initNavigation()