I am trying to use an ACTion ID to pull some information using Ajax from one of my pages. I have an ACT function in the exp_actions table with an ID of ‘38’. In my javascript code, I am trying to call it like so:
$(".preview").load("/report/index.php?ACT=38");
Currently, this code just tries to print out a test message in a div:
echo '<div><h3>This is a test.</h3></div>';
However, when I try to use the code, I receive this error:
Exception Caught
No such property: 'TMPL' on EllisLab\ExpressionEngine\Legacy\Facade
/Users/steve/Sites/ExpressionEngine311/system/ee/EllisLab/ExpressionEngine/Legacy/Facade.php:107
Stack Trace:
#0 ee/EllisLab/ExpressionEngine/Legacy/Facade.php(22): EllisLab\ExpressionEngine\Legacy\Facade->get('TMPL')
Any clues or hints anyone can give me? Is this a bug in EE or am I doing something wrong? This is version 3.2.1.
Thanks! Steve
Richard,
Yes, this is in an add-on I have developed. I used this same method in earlier versions of EE. Here is the complete code for the function called by the ACTion ID:
public function reporting() {
print_r($_POST);
exit;
//echo '<div><h3>This is a test.</h3></div>';
}
I have tested it with just the ‘echo’ command and just trying to print out the $_POST data. Neither work.
Thanks, Steve
A couple thoughts:
Is ee()->TMPL referenced someplace else in the add-on? Looks like there might be a typo in another part of the add-on causing the error message.
Try using a return statement in the method for the info you’re trying to get back:
public function reporting() {
$string = '<h1>' . ee()->input->post('title',TRUE) . '</h1>';
$string.= ee()->input->post('my_text',TRUE);
return $string;
}
Trying to return the string didn’t help.
I do use the ee()->TMPL at other places in the module. However, I don’t receive the error when I use any of the other functions, only when trying to use the ACTion ID. All of my other functions work correctly and without error.
As far as I know, when using the ACT Id, the template engine isn’t supposed to be loaded. Isn’t that correct?
I’m not certain, but I don’t think the jQuery $.load method is going to submit posted values. What happens when you use:
var request = $.ajax({
url: "/index.php/?ACT=38",
method: "POST",
data: $("#formSelector").serialize(),
dataType: "html"
});
// Additional scripting to write the returned data to your the page requesting it.
// More examples at http://api.jquery.com/jQuery.ajax/
You should probably also confirm that your upd.mymodule.php is creating the correct Class, method, and csrf_exempt values in the exp_actions table.
Richard, thanks for your help. I figured out what the problem was.
In the __construct() function for my module, I checked for a template variable since I use it in most of the public functions. However, with the ACTion ID, since the template engine isn’t loaded, this caused the error of there being no such variable as “TMPL”. If I comment out that code, it works fine. So, I’ll have to find another way to get that variable without it being in the construct.
Thanks! Steve
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.