Jump to content

Where to Add Code in Example Module?


WisTex

Recommended Posts

 

I have some already existing code that I would like to integrate with WHMCS. It is fairly simple old school code (query database, write HTML). Not the modern way of doing things, but the code works well, and I don't have the time nor budget to rewrite the entire script. I was hoping to enhance the code by tapping into the WHMCS login system and prepopulating fields with information stored in the WHMCS database.

 

I was looking at the sample code for creating an Addon Module, and it was not clear where you would paste such code. 

For example, if I wanted to execute the following code, where would you put it?

<?php
$message = "Hello World!";
echo $message;
?>

 Or are modules structured in such a way where old-school code won't work?  If that is the case, should I just create pages then?

Link to comment
Share on other sites

I read that whole section. The only examples I see use hooks and functions. The existing code is old-school. No functions. Just database query, output HTML. 

It appears it would go in addonmodule.php but that code seems to want functions. Do I just replace the function with HTML? Do I put the HTML in the function?

Edited by WisTex
Link to comment
Share on other sites

It appears modules would not be a suitable solution for my issue, for the following reasons:

  1. The example code outputs the WHMCS header and footer even though I don't need it.
  2. The template and the PHP code are separated in WHMCS and in my existing script, HTML and PHP are merged.

As such, it is actually impossible to just cut and paste the code from the other script into the module and have it work.

Since the whole purpose of integrating the other script is to not have to rewrite it, modules would not be an ideal way to do it.

Link to comment
Share on other sites

  • WHMCS Staff

Hi @WisTex,

For addon pages available within the Admin Area, you would need to add this to ~/lib/Admin/Controller.php - https://github.com/WHMCS/sample-addon-module/blob/master/modules/addons/addonmodule/lib/Admin/Controller.php

In the WHMCS Admin Area, the url would look like ~/admin/addonmodules.php?module=addonmodulename&action=page - the action variable calls the function in Controller.php.

For example, if you added the following function to Controller.php:

public function mynewpage($vars) {
    $message = "Hello World!";
    echo $message;
    return;
}

This would allow you to view "Hello World" from ~/admin/addonmodules.php?module=addonmodulename&action=mynewpage

Naturally, addonmodulename would be the name of your module.

I hope this helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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