Jump to content

Error too few arguments passed MenuRepository::addContext()


arobo

Recommended Posts

Hi,

After upgrading to WHMS 7.5, PHP7.2 and latest ioncube loaders we are now getting the following error from our custom client php pages and templates when using the following lines of code -

Menu::addContext();

Menu::primarySidebar('any_menu_item here_still errors');
Menu::secondarySidebar('any_menu_item here_still errors');

 

Results in error -

Too few arguments to function WHMCS\View\Client\Menu\MenuRepository::addContext(), 0 passed in /path_to_dir//vendor/illuminate/support/Facades/Facade.php on line 215 and exactly 2 expected in /path_to_dir/vendor/whmcs/whmcs-foundation/lib/View/Client/Menu/MenuRepository.php:0

 

Removing the above 3 lines of code and the php and template file in the client section displays correctly with no issues. No matter what menu item you have in the primary or secondary it still errors and seems like it is not passing the primary and secondary sidebar arguments in the file to display correctly?

 

Appreciate any assistance and help on the issue.

 

Thanks

Link to comment
Share on other sites

I'm sorry, I must be missing something .. I thought we were passing variables - specifically these -

Menu::primarySidebar('any_menu_item here_still errors');
Menu::secondarySidebar('any_menu_item here_still errors');

Please note the - any menu item could be any of these variables as per your documentation on your site -https://developers.whmcs.com/advanced/creating-pages/

as well as here - https://docs.whmcs.com/Editing_Client_Area_Menus

 

So for example using this code -

Menu::addContext();
Menu::primarySidebar('announcementList');
Menu::secondarySidebar('announcementList');

Will still give the error as though the variables are not being passed correctly.

You will notice that when we add these in the code - no matter what is put in the error reports there is no variable sent for some reason..

We want to add sidebars to the client page and we are adding contexts - however we are unable to do so - because it errors when we add the code. We know that this is the issue as when we delete those specific 3 lines of code the page displays correctly - except of course for the sidebars. Does this make more sense now?

Regards,

Link to comment
Share on other sites

Ok... sorry,  can you provide an example - we are using the exact template as shown here -

https://developers.whmcs.com/advanced/creating-pages/

Which worked fine previously to upgrading.

As per below, our template is based on the same example as based on this -

 

<?php

use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

define('CLIENTAREA', true);

require __DIR__ . '/init.php';

$ca = new ClientArea();

$ca->setPageTitle('Your Page Title Goes Here');

$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('mypage.php', 'Your Custom Page Name');

$ca->initPage();

//$ca->requireLogin(); // Uncomment this line to require a login to access this page

// To assign variables to the template system use the following syntax.
// These can then be referenced using {$variablename} in the template.

//$ca->assign('variablename', $value);

// Check login status
if ($ca->isLoggedIn()) {

    /**
     * User is logged in - put any code you like here
     *
     * Here's an example to get the currently logged in clients first name
     */

    $clientName = Capsule::table('tblclients')
        ->where('id', '=', $ca->getUserID())->pluck('firstname');
        // 'pluck' was renamed within WHMCS 7.0.  Replace it with 'value' instead.
        // ->where('id', '=', $ca->getUserID())->value('firstname');
    $ca->assign('clientname', $clientName);

} else {

    // User is not logged in
    $ca->assign('clientname', 'Random User');

}

/**
 * Set a context for sidebars
 *
 * @link http://docs.whmcs.com/Editing_Client_Area_Menus#Context
 */
Menu::addContext();

/**
 * Setup the primary and secondary sidebars
 *
 * @link http://docs.whmcs.com/Editing_Client_Area_Menus#Context
 */
Menu::primarySidebar('announcementList');
Menu::secondarySidebar('announcementList');

# Define the template filename to be used without the .tpl extension

$ca->setTemplate('mypage');

$ca->output();

 

Link to comment
Share on other sites

Ok - so how do I add menu sidebars then ... I want to add menu sidebars - specifically I want to do this -

Menu::primarySidebar('clientView');
Menu::secondarySidebar('clientAddFunds');

On the client php page I want to display. Adding this creates an error. I see nowhere on the development and php page example the Menu::addContent but there is a

Menu::addContext(); of which we are passing two parameters.

Removing it means no sidebars so what - (give example) - do I need to put in the PHP page to bring up two sidebars- one primary, and one secondary sidebar as it used to be able to do before upgrading to 7.5....

Please provide example on how on a client php page developed you would bring up the two sidebars as per above on the php page ...

Any help appreciated. Thanks

 

 

Link to comment
Share on other sites

  • WHMCS Developer
23 hours ago, arobo said:

Too few arguments to function WHMCS\View\Client\Menu\MenuRepository::addContext(), 0 passed in

says you are passing no parameters

1 hour ago, arobo said:

Menu::addContext();

Again, shows no parameters

18 minutes ago, arobo said:

Menu::addContext(); of which we are passing two parameters.

You state here you are passing parameters, but don't actually say what you are passing.

An example is difficult to provide - this is why the table on https://docs.whmcs.com/Editing_Client_Area_Menus#Context is provided. In the third column, the context required is listed with the type of context, and the value type being expected.

Screen Shot 2018-04-09 at 12.12.19.png

In this image, you see the sidebar name, the files this is used on by default, and then the context required. Here you can see, a context name in bold, and the type of context required. So, for clientView, you need to provide a "client" context that has the \WHMCS\User\Client type for the currently logged in client, or null for no client.

Menu::addContext('client', $clientVariable);

 

Link to comment
Share on other sites

Ahhhhhh ..yup. Right. I see the issue now. (Lightbulb moment)

So if I wanted a menu with upgrade and a specific service upgrade in the sidebar it would be -

Menu::addContext('serviceUpgrade', 'serviceidnumber?) ;

or something of this nature? Correct?

Thank you for the example :)

 

 

 

 

 

Link to comment
Share on other sites

  • WHMCS Developer

So the menu serviceUpgrade requires two contexts if you check the table (3rd column). Client and Service:

Menu::addContext('client', $clientVariable); // either \WHMCS\User\Client or null

Menu::addContext('service', $serviceVariable); // \WHMCS\Service\Service

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated