For my application in october cms I'd like to be able to send a mail with the click of a button. I call the php file with an ajax request, however when the button gets clicked I get the error 'class not found' for whichever class I use, doesn't matter which. I already added the file to .htaccess to be able to run it on the button click. I included all classes at the top of the file. Also when I turn it into an artisan command and run it with php artisan now:send:mail
it works without any issues. I already tried to run composer dump autoload
and composer dump autoload -o
. Code is down below, Any idea what I can do to make this work, or in what other way it could be done?
Thanks in advance!
Part of theme.js:
$.ajax({
url : '/plugins/test/notifications/ondemand/OnDemand.php'
}).done(function(data) {
console.log(data);
});
OnDemand.php:
<?php
namespace Test\Notifications\OnDemand;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Test\Poles\Components\Metrics;
use October\Rain\Argon\Argon;
class OnDemand
{
public function send()
{
$date = Argon::now(config('app.timezone'))->format('Y-m-d');
// get some data
$array = ['date' => $date, 'score' => $score, 'CO2' => $CO2, 'scorecar' => $scorecar, 'scorebike' => $scorebike];
$email = "[email protected]";
Mail::sendTo($email, 'daily.mail', $array);
}
}
$mail = new OnDemand;
$mail->send();
php
. so there is no way for october cms to initialise itself, you are using October cms functinality inside it so its obvious it will not find the classes. probably you can includeautoload file.
BUT bease solution would be add component to plugin which can handle ajax request and then useOctoberCms ajax framework
to do this. – Hardik Satasiya