• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call to undefined method respond()

#1
Hi,

I created a controller as following. It works fine but when I send API request through Postman I get error "Call to undefined method respond()". What mistake I am making? 

PHP Code:
use App\Controllers\BaseController;
use 
App\Models\MyModel;
use 
CodeIgniter\API\ResponseTrait;

class 
Myclass extends BaseController {

    public function mytask() {
        
        $data 
$this->request->getPost();
        $model = new MyModel;
        $msg $model->save_data($data);
                    
        
if ($this->apicall == "yes") {

            return $this->respond($msg); // API Call
            
        
} else {

            return view('message_view'$msg); // Not API Call, return View

        }
    }


Reply

#2
You forgot to place the trait call:

Code:
class Myclass extends BaseController {
    use ResponseTrait;

public function mytask...
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.