I would like to send an e-mail for registration via CakePHP.

Asked 1 years ago, Updated 1 years ago, 46 views

I would like to send an e-mail with a link for this membership registration to the e-mail address entered in the membership registration form via CakePHP.

Error: SQLSTATE [42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that responses to your MySQL server version for the right syntax to use getActivationHash' at line 1: SQLAction

You are getting the error

I have little experience with CakePHP, so I can't make a breakthrough.
Please let me know if there is anyone who knows the problem using the code below.

public$components=array('Auth');

public function beforeFilter() {
    $this->Auth->allow('signup');
}

public function signup()
{
    if($this->request->is('post'))){
        if($this->User->save($this->data)){
            $url = 'activate/'.$this->User->id.'/'.$this->User->getActivationHash();
            $url = Router::url($url, true);

            $email = new CakeEmail();
            $email->from(array('[email protected]'=>'Sender'));
            $email->to($this->data['User']['email']);
            $email->subject('Registration mail');
            $email->send($url);

            $this->Session->setFlash('Registration successful');
        } else {
            $this->Session->setFlash('Error');
        }
    }
}

Cake/conf/Email.php

class EmailConfig {

public$default=array(
    'transport' = > 'Mail',
    'from' = > 'you@localhost',
    // 'charset' = > 'utf-8',
    // 'headerCharset' = > 'utf-8',
);

public$smtp=array(
    'transport' = > 'ssl://Smtp.gmail.com',
    'from'=>array('site@localhost'=>'My Site'),
    'host' = > 'localhost',
    'port' = > 587,
    'timeout' = > 30,
    'username' = > 'root',
    'password' = > 'root',
    'client' = > null,
    'log' = > false,
    // 'charset' = > 'utf-8',
    // 'headerCharset' = > 'utf-8',
);

mysql cakephp

2022-09-30 17:43

1 Answers

If you invoke a method that is not implemented in a CakePHP 2.x model class, an SQL statement is constructed with that method name.

The getActivationHash method is implemented in the User class, but this is what happens because the $this->User is not a User class.
For verification purposes, check the class name, such as debug(get_class($this->User)), which should be an AppModel class.

The controller in CakePHP 2.x has a singular model of the controller name by default, but if the model class is not found in a conventionally aligned location at the time of the call, the AppModel class is used as an alternative.

Ensure that the User class is located in a conventionally compliant location (app/Model/User.php).


2022-09-30 17:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.