Jump to content
arobo

Error too few arguments passed MenuRepository::addContext()

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

Share this post


Link to post
Share on other sites

addContext needs variables like the error states. If you aren't adding any contexts, then you don't need to use that line.

Share this post


Link to post
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,

Share this post


Link to post
Share on other sites

Your code specifically shows that you aren't passing any variables to the Menu::addContent method call.

Share this post


Link to post
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();

 

Share this post


Link to post
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

 

 

Share this post


Link to post
Share on other sites
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);

 

Share this post


Link to post
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 :)

 

 

 

 

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Thanks guys. I was trying to figure out what part exactly in the custom page that was causing this.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Similar Content

    • By earthgirlllc
      Hi there, I've come across an error I can't seem to find a solution for.  
       
      From this page: https://**WHMCS INSTALL** /admin/configaddonmods.php?activated=true when I save an addon configuration, I get the following error: 
      Error Updating Value On the page:  https://**WHMCS INSTALL**/billing/admin/configaddonmods.php
      I've turned on error reporting and I don't get anything more verbose - just this. I upgraded to the most recent release to see if I could resolve it. The update went smoothly but the error is still present. Any ideas on how to troubleshoot this would be appreciated.
       
      Thanks!
      Amber
    • By descom
      Hello,
      I try this code:
      $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://******/api/includes/api.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( [ 'action' => 'GetClients', // See https://developers.whmcs.com/api/authentication 'identifier' => '*****', 'secret' => '*****', 'search' => 'domain', 'responsetype' => 'json', ] ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); var_dump($response); But i get this error: {"result":"error","message":"An admin user is required"}
      My Ip is listed in Api Alloweds Ips and I have whmcs v7.9.1
      Whats is the problem?
      Thanks,
      Cesar
    • By JoshuaR
      Hi so I got this error when I click either DNSsec or DNS.

      It gives me this fatal error.
        Anybody knows why it gives that error?
    • By Dimitra
      Hello again,
      There is another error i just encountered.
      Well, I loggin in clientarea as client and check my domain - it is an active domain. When I click the Domain Contact Info link from the sidebar (clientarea.php?action=domaincontacts&domainid=7), I get the Oops, something went wrong page.
      The error I see is:
      "TypeError: Argument 1 passed to normaliseInternationalPhoneNumberFormat() must be of the type array, bool given, called in /home/hshost/public_html/clientarea.php on line 0 and defined in /home/hshost/public_html/includes/clientfunctions.php:0
      Stack trace:
      #0 /home/hshost/public_html/clientarea.php(0): normaliseInternationalPhoneNumberFormat(true)
      #1 {main}"
      If I get it correctly, it has something to do with the International phone codes. When I created this client, the phone codes feature was enabled. Yestarday I disabled it and now I get this error. I tried enabling again the feature and changing the phone from tha database, but nothing.
      When The feature was enabled (before I disable it), I hadn't visited the Domain Contact Info, so i don't know if it was working at that time.
      Any ideas why this is happening or how it can be fixed;
       
      Thank you.
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • 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