Welcome Guest, Not a member yet? Register   Sign In
Creating controller both for CRUD and API REST
#1

(This post was last modified: 04-04-2022, 03:39 PM by kabeza.)

I'm builing 2 controllers
Let's say Project entity

One controller will handle the CRUD, Views, etc.
app\Controllers\Projects.php

PHP Code:
<?php

namespace App\Controllers;

class 
Projects extends BaseController
{
    public function 
index()
    {
    }


The other, will handle the API REST Resources
app\Controllers\api\Project.php

PHP Code:
<?php
namespace App\Controllers;

use 
CodeIgniter\RESTful\ResourceController;

class 
Project extends ResourceController
{
    protected 
$modelName '';
    protected 
$format    'json';
    public function 
index()
    {
    } 

app\Config\Routes.php

Code:
$routes->get('/projects', 'Projects::index');
$routes->resource('/api/project', ['only' => ['index', 'show']]);

When I call the api route with Browser or Postman, I get

ErrorException #64
Cannot declare class App\Controllers\Project, because the name is already in use in D:\www\test\app\Controllers\api\Project.php on line 0

I don't understand it because classNames differ in both Controllers. Any clues? Maybe routes is bad configured?
Thanks for any suggestion
Reply


Messages In This Thread
Creating controller both for CRUD and API REST - by kabeza - 04-04-2022, 03:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB