Validation using Controller


I have to validate data in controller.
and display the validator message in view.

I have not used default cakephp functions like save(), patchEntity().

How can I do this?


try this:


Bad idea.
You will not be able to validate data of same model in other controllers without code duplication.


Your query lack explanation.

Answer to your 2nd query for custom message display.

There is this thing called Flash located in:

create yourfunctionName.ctp file in above directory, and copy the following code in it.

    $message = h($message);
<div class="message success" onclick="this.classList.add('hidden')"><?= $message ?></div>

Then use the following code:

$this->Flash->yourfunctionName('This is custom message.');

in your Controller’s method.
For e.g.

public function functionName(){
 if( /* If some condition is true/false */ ){
    //print or Flash this message
   $this->Flash->yourfunctionName('This is custom message.');