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

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
Guest
This topic is now closed to further replies.

  • Similar Content

    • 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.
    • By hanstavo
      When I tried to do a test checkout I realized that I cant continue. I get an error about invalid tax percentage, but I don't even have tax setup. I am using WHMCS 7.4.2
      I get the error no matter what payment gateway, and I have tried a fresh install of the checkout.tpl file and a bunch of other files that is included on multiple pages such as common and the sidebars.
      When I enable error reporting, I get the following stack trace:

      WHMCS\Exception\Billing\BillingException: Invalid tax percentage: in /home/myuser/public_html/vendor/whmcs/whmcs-foundation/lib/Billing/Tax.php:0
      Stack trace:
      #0 /home/myuser/public_html/vendor/whmcs/whmcs-foundation/lib/Billing/Tax.php(0): WHMCS\Billing\Tax->validateTaxPercentage(NULL)
      #1 /home/myuser/public_html/includes/invoicefunctions.php(0): WHMCS\Billing\Tax->setLevel1Percentage(NULL)
      #2 /home/myuser/public_html/includes/processinvoices.php(0): updateInvoiceTotal(0)
      #3 /home/myuser/public_html/includes/processinvoices.php(0): createInvoicesProcess(false, true, '')
      #4 /home/myuser/public_html/includes/orderfunctions.php(0): createInvoices(1, true, '', Array)
      #5 /home/myuser/public_html/cart.php(0): calcCartTotals(true)
      #6 {main}
    • By hanstavo
      Can Someone Please help me? When I tried to do a test checkout I realized that I cant continue. I get the following error, but I don't even have tax setup. I am using WHMCS 7.4.2
      Oops!
      Something went wrong and we couldn't process your request.
      Please go back to the previous page and try again.
      If the problem persists, please contact us.
      « Back to Homepage
      For additional assistance, please reference the WHMCS TroubleShooting Guide »

      WHMCS\Exception\Billing\BillingException: Invalid tax percentage: in /home/myuser/public_html/vendor/whmcs/whmcs-foundation/lib/Billing/Tax.php:0
      Stack trace:
      #0 /home/myuser/public_html/vendor/whmcs/whmcs-foundation/lib/Billing/Tax.php(0): WHMCS\Billing\Tax->validateTaxPercentage(NULL)
      #1 /home/myuser/public_html/includes/invoicefunctions.php(0): WHMCS\Billing\Tax->setLevel1Percentage(NULL)
      #2 /home/myuser/public_html/includes/processinvoices.php(0): updateInvoiceTotal(0)
      #3 /home/myuser/public_html/includes/processinvoices.php(0): createInvoicesProcess(false, true, '')
      #4 /home/myuser/public_html/includes/orderfunctions.php(0): createInvoices(1, true, '', Array)
      #5 /home/myuser/public_html/cart.php(0): calcCartTotals(true)
      #6 {main}
    • By So, who am I ?
      Hello
      System returns incorrect information about a domain while checking availability for transfer.
      When I check domains for transfer it says that every domain is 'Available', except the ones that aren't registered at all and says 'Not Available', the response is true in this case. Domain that is transferring to me from another registrar should be 'Available' as well (and it works fine too), but domain that's transferred to me shouldn't be available for transfer on my site again, cuz how can one transfer from myself to myself, right?
      Not quite sure how CheckAvailability works for transfer, when it's for register, it uses WHOIS and gets response from it, but when it comes to Transfer, I'm not sure how system works, my theory is that it checks 'tbldomains' table in database to see if domain has 'Active' status in database and avoid double transfer, but it needs to use WHOIS as well to check if domain is registered at all and is available for transfer. Again, not sure if my theory is correct, it's just my guess.
      WHOIS works fine when it comes to registration and it was working fine for Transfer as well until now, I've not made any changes but somehow CheckAvailability for Transfer stopped working properly.
      Couldn't find any detailed documentation, any help would be much appreciated!
    • By akust0m
      Hey,
      When navigating to Utilities > Update WHMCS, I am greeted with the 'Oops! Something went wrong..' error.
      Temporarily displaying errors gives the following:
      TypeError: Argument 1 passed to WHMCS\View\Admin\HealthCheck\HealthCheckRepository::checkUpdaterRequirements() must be an instance of WHMCS\Installer\Update\Updater, string given, called in /var/www/vhosts/my.example.com/httpdocs/admin/update.php on line 0 and defined in /var/www/vhosts/my.example.com/httpdocs/vendor/whmcs/whmcs-foundation/lib/View/Admin/HealthCheck/HealthCheckRepository.php:0
      Stack trace:
      #0 /var/www/vhosts/my.example.com/httpdocs/admin/update.php(0): WHMCS\View\Admin\HealthCheck\HealthCheckRepository->checkUpdaterRequirements('67108864', NULL)
      #1 {main}
      How would I go about resolving this error?
      Thanks!
  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

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