-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CakePhp 4 ($mailer) must be of type Cake\Mailer\Mailer, Cake\View\ViewBuilder given #951
Comments
You have to change your code to look more like
|
Ha yes, it works. It seems that the issue is just on documentation, then :) |
Which documentation is incorrect? |
The examples in the mail-preview debug-kit page, which are the same than in cakephp 3 : class UserMailer extends Mailer
{
public function welcome($user)
{
return $this // Returning the chain is a good idea :)
->to($user->email)
->subject(sprintf("Welcome %s", $user->name))
->template("welcome_mail") // By default template with same name as method name is used.
->layout("custom")
->set(["user" => $user]);
}
} and class UserMailPreview extends MailPreview
{
public function welcome()
{
$this->loadModel("Users");
$user = $this->Users->find()->first();
return $this->getMailer("User")
->welcome($user)
->set(["activationToken" => "dummy-token"]);
}
} |
Hi,
I use mailer and mail preview since cake 3, and while trying to do same with cakephp 4 I just ran into something weird.
I got a UserMailer with many method (devis, contact, confirmation, etc..). In each of these methods I set something like :
(Switching to cake 4, I was forced to add the call to "->viewBuidler()" before "setTemplates", "setLayouts" and "addHelpers".)
And then, in my UserMailPreview I use :
And unfortunately, I ran in :
'DebugKit\Mailer\PreviewResult::__construct(): Argument #1 ($mailer) must be of type Cake\Mailer\Mailer, Cake\View\ViewBuilder given'
I do understand that yes, my "devis" method return a viewBuilder object, but how can I assign templates, layout and helpers without it ??
The text was updated successfully, but these errors were encountered: