Jump to content
dtravlos

addon module admin area

Recommended Posts

Hello,

I am trying to create an addon module only for the admins. Can you help me on how I can render templates from each controller action instead of simly echo the content? On the sample addon it says @see AddonModule\Admin\Controller::index() but I can't find the docs... 

Also for ajax calls I can simple create actions and just echo the result as json? 

Thanks

Share this post


Link to post
Share on other sites

In the sample addon module  open file: modules/addons/addonmodule/lib/Admin/Controller.php  .  Then find the "index" function.  That's all they mean by "see" as there isn't much more

In the addon modules's _output function that is used for the admin, it only expects HTML / string as a return and thus why they build it up using a string variable in the index function.  You could use the smarty engine, feed it a template file local to the addon's directory, assign the variables needed, and then use the fetch function instead of display to then get the HTML, which you then return and WHMCS spits it out.   I may have another post that details this a bit more.

Share this post


Link to post
Share on other sites

Thanks it worked! I am trying to create an ajax call but the response sends the entire admin page 😕 

Is there any way to have actions tha return only the json response i need and not the entire admin page? 

Thanks!

Share this post


Link to post
Share on other sites
4 hours ago, dtravlos said:

Is there any way to have actions tha return only the json response i need and not the entire admin page? 

I would either create a new file for ajax calls or do a "exit;" after you echo the json output. That should work.

Share this post


Link to post
Share on other sites
<?

/* Cut... */

function YourModule_output($vars)
{
    if ($_POST['ajax'])
    {
        $result = doSomething();
        header('Content-Type: application/json');
        echo json_encode($result);
        die();
    }
}

 

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 and understand your posts will initially be pre-moderated