Welcome Guest, Not a member yet? Register   Sign In
Controller or its method is not found: \\App\\Controllers\\Home::index
#12

(This post was last modified: 03-07-2022, 06:51 PM by spreaderman. Edit Reason: adding clarity )

Thank you.  Why would one work and not the other though?

Also, still cannot get post to work.  I am not using postman.  Using the same code as before;

PHP Code:
    public function testmethod(){
 
helper(['curl']);
 
$rest_api_base_url 'https://development.example.com';
 
$get_endpoint '/api/v1/add';
 
$response $this->perform_http_request('POST'$rest_api_base_url $get_endpoint);
 
print_r($response); 
    

Route as follows;

PHP Code:
$routes->group("/api/v1", ["namespace" => 'App\Controllers\Api\V1'] , function($routes){
 
    $routes->group("user", function($routes){
    $routes->get("list""User_Controller::index");
    $routes->post("add""User_Controller::register");
 
    }
 );
}); 

register method as follows;


PHP Code:
namespace App\Controllers\Api\v1;
use 
CodeIgniter\RESTful\ResourceController;
use 
App\Models\UserModel;
use 
App\Entities\UserEntity;

    public function register(){
 
  $user = new UserEntity($this->request->getPost());
    //$user->startActivation();
    if ($this->UserModel->insert($user)){
        $this->sendActivationEmail($user);
            $response =[
            'status'    => 200,
            'message'  => 'User registed.  Check email to activate account.',
            'error'    => false,
            'data'      => []
            ];
    } else {
        $response =[
            'status'    => 500,
            'message'  => $this->UserModel->errors(),
            'error'    => true,
            'data'      => []
            ];
    }
    return $this->respondCreated($response);
    }
    public function index(){
        $response = [
            'status'    => 200,
            'message'  => 'Employee List',
            'error'    => false,
            'data'      => $this->UserModel->orderBy('id''DESC')->findAll(),
        ];
        return $this->respondCreated($response);    
    



https://development.example.com/api/v1/user/list - works!
https://development.example.com/api/v1/user/add - doesn't work from testmethod or postman.  It returns a blank screen and CI debugger bar.  Have tried with debugger bar off too and doesn't work as expected.


Any pointers appreciated.
Reply


Messages In This Thread
RE: Controller or its method is not found: \\App\\Controllers\\Home::index - by spreaderman - 03-07-2022, 06:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB