2

I am trying to make a function inside of my UsersController.php that a curl request can call, but when return is called, the page not found error is rendered. I was wondering what I can use to stop any renders of a view. With just echo "hello world", it works, but returns make the page not found view render.

public function upgrade() {
    $this->autoRender = false;  
    return 'hello world';
}

// From another site
$ch = curl_init();

if($ch == false){
    throw new Exception('failed to init');
}

curl_setopt_array($ch, array(
    CURLOPT_URL => 'example.com/users/upgrade',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false
));
$output = curl_exec($ch);
echo $output;

$output is echoing a page not found instead of hello world.

Sammy Tang
  • 23
  • 3
  • 2
    Controller actions are not allowed to return strings, that will result in an exception (for details make sure you have debug mode enabled, or check your logs). Controllers should also never echo data, if you want to return custom contents without using a view, then return a response object: **https://stackoverflow.com/questions/42378793/how-to-output-custom-http-body-contents-with-cakephp-3-4-echoing-causes-unable/42379581#42379581** – ndm Feb 14 '20 at 00:57

0 Answers0