Im trying to send a email with a list of companies that have the pending or waiting status.
This list is already collected in the following function:
public static function getCompaniesAwaitingCheck()
{
$awaitingChangeApproval = self::getAwaitingChangeApproval();
$awaitingPublication = self::getAwatingPublication();
return array_merge($awaitingChangeApproval, $awaitingPublication);
}
Now I want to use that function to put in the email. I have made a separate class for this (AdminPendingApprovalNotification.php)
In there is the following function:
public function notifyPendingApproval()
{
$dailyClaimMailTitle = get_field("daily_claim_overview_mail_title", 'options');
$dailyClaimMailText = get_field('daily_claim_overview_mail_text', 'options');
$dailyClaimMailAddress = get_field('daily_claim_overview_mail', 'options');
$company = new Company();
$pendingCompany = $company->getCompaniesAwaitingCheck();
wp_mail(
$dailyClaimMailAddress,
ecs_get_template_part('views/email/template', [
'title' => $dailyClaimMailTitle,
'text' => $dailyClaimMailText, $pendingCompany,
], false),
['Content-Type: text/html; charset=UTF-8']
);
}
When I dd($pendingCompany); I get the error:PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Models\Model::__construct(), 0 passed in Emails/AdminPendingApprovalNotification.php on line 16 and exactly 1 expected
line 16: $company = new Company();
Unfortunately can’t get it to work, I’m a beginner, some help would be appreciated. Thanks!
Your method getCompaniesAwaitingCheck is static, so you should call it like:
$pendingCompany = Company::getCompaniesAwaitingCheck();
An error occured because your Company class requires arguments in the __construct method, which you didn't provide.
Related
My error: I am facing this issue quite long time and found one solution in stackoverflow but it doesn't work. I need solution to work with laravel , php 7+ and mysql.
It is showing below error:
ErrorException
Trying to get property 'app_layout' of non-object
Error page consists following code and i tried all solutions in stack overflow but no us. I want to show my layout without any error here.
Error in the script\app\Http\Controllers\MainBaseController.php:26
code on the page is : error line highlighted in BOLD below
use Illuminate\Support\Facades\Schema;
use Froiden\Envato\Traits\AppBoot;
class MainBaseController extends Controller
{
public function __construct()
{
parent::__construct();
// Settings
$this->settings = Setting::first();
$this->year = Common::year();
$this->bootstrapModalRight = true;
$this->bootstrapModalSize = 'md';
**$this->siteLayout = $this->settings->app_layout; // top, sidebar**
$this->forbiddenErrorView = 'errors.403';
$this->showFooter = true;
$this->rtl = $this->settings->rtl;
// Status
$this->statusArray = [
'enabled' => __('app.enabled'),
'disabled' => __('app.disabled')
];
// Setting assets path
$allPaths = Common::getFolderPath();
foreach($allPaths as $allPathKey => $allPath)
{
$this->{$allPathKey} = $allPath;
I am placing error part of the code above , if you need any other parts i will provide
I got this error when trying to redirect to another method
Type error: Argument 1 passed to
Symfony\Component\HttpFoundation\ResponseHeaderBag::__construct() must
be of the type array, integer given, called in
/proyect/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Response.php
on line 199
But I'm sending an empty array
return new RedirectResponse('persons', array(), UrlGeneratorInterface::RELATIVE_PATH);
Any help?
Is this the HttpFoundation\RedirectResponse class ? Your instanciation looks wrong.
// Symfony\Component\HttpFoundation\RedirectResponse
public function __construct($url, $status = 302, $headers = array())
{
...
}
Your third parameter is an integer, when an array is expected. The RedirectResponse constructor calls its parent, the Response constructor, and this code is executed:
// Symfony\Component\HttpFoundation\Response
public function __construct($content = '', $status = 200, $headers = array())
{
$this->headers = new ResponseHeaderBag($headers);
...
}
This is your error, you're using an integer (UrlGeneratorInterface::RELATIVE_PATH, equals to 2) when the expected value is an array of response headers.
As answered by #Cerad the correct solution is to use the redirectToRoute method, but it'll redirect you to an absolute path:
return $this->redirectToRoute('persons', array());
Or, if you still want to use the RedirectResponse with a relative path:
$url = $this->generateUrl('persons', array(), UrlGeneratorInterface::RELATIVE_PATH);
return new RedirectResponse($url);
I don't find exactly where is my problem. It seems the objectinfo is empty and
I have this error on.
Fatal error: Call to undefined method objectInfo::objectInfo() on this line $bInfo->objectInfo($banner);
My sql request work fine and I verified
There my code where is the problem.
Tk
$parameters = array('expires_date' => '',
'date_scheduled' => '',
'banners_title' => '',
'banners_url' => '',
'banners_group' => '',
'banners_target' => '',
'banners_image' => '',
'banners_html_text' => '',
'expires_impressions' => '',
'banners_title_admin' => ''
);
$bInfo = new objectInfo($parameters);
$bID = HTML::sanitize($_GET['bID']);
$Qbanner = $OSCOM_PDO->prepare('select banners_title,
banners_url,
banners_image,
banners_group,
banners_target,
banners_html_text,
status,
date_format(date_scheduled, "%Y-%m-%d") as date_scheduled,
date_format(expires_date, "%d/%m/%Y") as expires_date,
expires_impressions,
date_status_change ,
customers_group_id,
languages_id,
banners_title_admin
from :table_banners
where banners_id = :banners_id
');
$Qbanner->bindInt(':banners_id', (int)$bID);
$Qbanner->execute();
$banner = $Qbanner->fetch();
$bInfo->objectInfo($banner); // pb is here
As par i know this Fatal error occur due to the updated version of the php.
Earlier, we are able to autoload the class property by using the same function name of the class name.
In Earlier varsion of PHP, we can able to call or define the Same Function name of the class name.
But new the Latest version of php we can not do that. if we use the same function name of the class name and if we call this function name then it give us the fatal error like you received in this post.
So the solution is as follow.
Go to the class objectInfo ( or whatever you have )
your class file is currently have
class objectInfo {
function objectInfo($object_array) {
your function code here.....
}
}
Change the function name from objectInfo to __construct. so the entire class is looking like as below
class objectInfo {
function __construct($object_array) {
your function code here.....
}
}
currently you call the function like
$bInfo = new objectInfo($parameters);
$bInfo->objectInfo($banner);
so change above code as below.
$bInfo = new objectInfo($parameters);
$bInfo->__construct($banner);
so finally hope that your error will be solved.
The line $bInfo = new objectInfo($parameters); created a new instance of the objectInfo class. Then you attempt to call the method objectInfo() of this class. The error message just tells you that this class has no such method. Can you show the source code for the class objectInfo?
I created a contact form on my classified ads website.
I use the following function to get the uploader email :
public function uploadermail()
{
return $this->User_id?$this->User->email:lang('anonymous');
}
It works fine and I get the result using an echo :
<?php echo $image->uploadermail(); ?>
Then I use a function to send the mail :
public static function sendmail_anon()
{
$form = new Form('sendmail_anon');
$form->field('email', 'text', array
(
'valid_email' => true
));
$form->field('message', 'textarea', array
(
'min_length' => 25
));
if($data = $form->validate())
{
$envoi = array
(
'message' => $data['message'],
'email' => $data['email']
);
mail($data['email'], lang('account_details'), lang('email_contact', $envoi), 'From: noreply#'.$_SERVER['HTTP_HOST']);
}
return $form;
}
The problem is that this is sending the mail to the e-mail from the form field.
I would like to replace $data['email'] and insert the uploadermail instead. I tried :
mail($image->uploadermail(), lang('account_det.....
And it returns the following error :
Fatal error: Call to a member function uploadermail() on a non-object
Is it possible to do and how should I writte it exactly ?
I tried :
mail($uploadermail,....
And it doesn't returns errors, but didn't received any mail, how can I check what exactly contains $uploadermail on the browser ?
This means that $image is not an class instance. So you cannot do $image->uploadermail().
You can check it out by doing: var_dump($image);
After posting your full code I see you are accessing that function from public static function sendmail_member():
mail($image?$image->uploadermail():$data['email'], lang('account_details'), lang('email_contact', $envoi), 'From: noreply#'.$_SERVER['HTTP_HOST']);
However $image is never declared (/ instantiated) in that scope. Upon further investigation I see that there is a method called uploadermail in the correct class which I guess you are trying to access.
So to access that method you should do:
self::uploadermail()
or
$this->uploadermail()
PS
You should really try to prevent using statics. Static stuff are basically globals and they tightly couple you code and it prevent the L in SOLID programming.
You should instantinate an object for $image before usage! e.g.
$image = new ...
or
$image = x.GetImage(...
I'm trying to send an email from a CakePHP shell just as you would from the Controller.
Most of the code below was adapted from this dated article on the Bakery and it's comments. The email is sending, however the line $controller->set('result', $results[$i]); throws the following notices:
Notice: Undefined property:
View::$webroot in
/home/jmccreary/www/intranet.sazerac.com/cakephp/cake/libs/view/view.php
on line 813
PHP Notice: Undefined
variable: result in
/home/jmccreary/www/intranet.sazerac.com/cakephp/app/views/elements/email/text/nea/task_reminder_it.ctp
on line 2
So I'm not getting any of the variables passed to my email view.
How can I do this, ideally following the Cake conventions?
class NotificationShell extends Shell {
var $uses = array('Employee', 'Task');
function main() {
// run if no action is passed
}
function nea_task_reminder() {
// build Task to Employee relationship
$this->Task->bindModel(array('belongsTo' => array('Employee' => array('className' => 'Employee', 'foreignKey' => 'object_id'))));
$results = $this->Task->find('all', array('conditions' => array('application_id' => 1, 'completed_by_id' => 0), 'contain' => array('Employee' => array('Contact', 'Position'))));
$count = count($results);
if ($count) {
App::import('Core', 'Controller');
App::import('Component', 'Email');
$controller =& new Controller();
$email =& new EmailComponent();
$email->startup($controller);
// send email
$email->from = Configure::read('Email.from');
$email->to = 'jmccreary#whatever.com';
$email->replyTo = 'no-reply#whatever.com';
$email->template = 'nea/task_reminder_it';
$email->sendAs = 'text';
for ($i = 0; $i < $count; ++$i) {
$email->subject = 'NEA Notification: Task Reminder for ' . $results[$i]['Employee']['Contact']['full_name'];
$controller->set('result', $results[$i]);
$email->send();
}
}
}
}
The problem is the way you're initializing the EmailComponent class. If you look at the source code, the startup() method doesn't actually have a body so it does nothing. Your controller isn't actually assigned to the EmailComponent. The problem isn't $controller->set('results', ...);. You need to use EmailComponent::initialize() instead of EmailComponent::startup().
$controller =& new Controller();
$email =& new EmailComponent(null);
$email->initialize($controller);
Sources:
Comments section of http://bakery.cakephp.org/articles/Jippi/2007/12/02/emailcomponent-in-a-cake-shell
EmailComponent::startup() Source
If you're using CakePHP 2.x, you can ditch the EmailComponent entirely and use the CakeEmail class instead.
App::uses('CakeEmail', 'Network/Email');
class NotificationShell extends Shell {
public function send() {
$email = new CakeEmail();
}
}
That entirely avoids all the thorny issues of loading components inside a shell. For email at least.
If you're using CakePHP 2.x, try to use CakeEmail instead.
CakeEmail#viewVars() provides setting variables to template.
Here is example using CakeEmail from Shell.
https://gist.github.com/tsmsogn/cee9cef2e851e7684021
Try this.
App::import('Core', 'Controller');
App::import('Component', 'Email');
$this->Controller =& new Controller();
$this->Email =& new EmailComponent(null);
$this->Email->initialize($this->Controller);
//use set function as below
$this->controller->set('result', $results[$i]);
for more reference click on below link:
http://ask.cakephp.org/questions/view/cron_shell_-_mail