Welcome Guest, Not a member yet? Register   Sign In
Resource Controller problem with show method and uri param
#1

(This post was last modified: 05-05-2022, 10:30 AM by kabeza.)

I have the following route configured in app/Config/Routes.php

Code:
$routes->resource(
    '/api/project',
    [
        'only' => ['index', 'show'],
        "controller" => "Api\Project"
    ]
);

Then I have the Project controller in app/Controllers/Api/Project.php

Code:
<?php
namespace App\Controllers\Api;
use CodeIgniter\RESTful\ResourceController;
class Project extends ResourceController
{
    protected $modelName = 'App\Models\ProjectModel';
    protected $format    = 'json';

    public function index()
    {
        return $this->respond($this->model->findAll());
    }

    public function show($id = null)
    {
        return $this->respond($id);
    }
}

When I run
http://myapp/api/project

I get all the records in json, all works fine

But when running this url
http://myapp/api/project/show/26

I get as output show and not 26 value.

What could be happening ?

How should I modify the route in case show method has more parameters?

Thanks a lot

Well

I must have looked like an a*****e

For anyone having similar "issue" the correct url for show method in resourceController is

http://myapp/api/project/26

Because looking several times the way routes are generated, the show route is generated without the show word

https://codeigniter.com/user_guide/incom...l.html#id4
Reply


Messages In This Thread
Resource Controller problem with show method and uri param - by kabeza - 05-05-2022, 09:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB