Jump to content
cseamiya

error in sub menu in a main menu link

Recommended Posts

Hi,

i want to provide ssl services and mail services menu link in client area navigation bar, but i want to show it in sub menu of services. and in hook i submit it and it will work fine, but after that when i go to client site and logout it show Ooops... something error.

what should i do?

Share this post


Link to post
Share on other sites
1 hour ago, cseamiya said:

what should i do?

enable display errors from general settings -> other and see what the actual error is.

also, post the code (with screenshots of where it should be) and i'll tell you what's wrong with it - though even without seeing the code, I could hazard a reasonable guess at what you're doing wrong.

Share this post


Link to post
Share on other sites
3 hours ago, brian! said:

enable display errors from general settings -> other and see what the actual error is.

also, post the code (with screenshots of where it should be) and i'll tell you what's wrong with it - though even without seeing the code, I could hazard a reasonable guess at what you're doing wrong.

when i put this code in hook, it will show in client area but after click on logout button it show error, and the whole site is not opening, 

Share this post


Link to post
Share on other sites
3 minutes ago, cseamiya said:

when i put this code in hook, it will show in client area but after click on logout button it show error, and the whole site is not opening, 

then you need to post the hook code that you're using - I can't comment on code that I can't see!

Share this post


Link to post
Share on other sites
3 minutes ago, brian! said:

then you need to post the hook code that you're using - I can't comment on code that I can't see!

here is the code i use in hook:

$primaryNavbar->addChild('Dashboard')->setOrder(1)->setUri('https://www.example.com/client/clientarea.php');        //(this is use for a menu name dashboard)
    $primaryNavbar->addChild('Services')->setOrder(20);         
            $primaryNavbar->getChild('Services')->addChild('SSL')->setUri('https://www.example.com/ssl/')->setOrder(3);
            $primaryNavbar->getChild('Services')->addChild('Mail Services')->setUri('https://www.example.com/mail-services/')->setOrder(4);

 

when i put this whole code from addChild(services to setUri url link)) it will show sub menu but when i click logout button it show error.

Quote

 

 

Share this post


Link to post
Share on other sites

basically you need to check that a parent (Services) exists before you try to modify it... when the client is logged in, Services exists... when they are logged out, Services does not exist... and that will cause an error.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
	if (is_null($primaryNavbar->getChild('Dashboard'))) {
		$primaryNavbar->addChild('Dashboard')
			->setOrder(1)
			->setUri('https://www.example.com/client/clientarea.php');  
	}
	if (!is_null($primaryNavbar->getChild('Services'))) {
		$primaryNavbar->getChild('Services')
			->addChild('SSL')
			->setUri('https://www.example.com/ssl/')
			->setOrder(3);
	}
	if (!is_null($primaryNavbar->getChild('Services'))) {
		$primaryNavbar->getChild('Services')
			->addChild('Mail Services')
			->setUri('https://www.example.com/mail-services/')
			->setOrder(4);
	}
});

so the hook does 3 things..

  1. checks if "Dashboard" already exists - if it doesn't, it creates the link (though it's the same as the "Home" link - unless you've changed that).
  2. checks if the "Services" parent exists - if it does, then it adds the SSL child link to it.
  3. checks if the "Services" parent exists - if it does, then it adds the Mail Services child link to it.

s00Rx6r.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines