Welcome Guest, Not a member yet? Register   Sign In
second Model doesn't work
#1

Hello,
i have an issue when i created a second Model Named FOLDERMODEL, based on a working Model DOCMODEL,
I hade this error Message :     "message": "Call to undefined method App\\Controllers\\APIFolder::find()",
Can some give a help THANKS a lot Codeigniter Family.
Quote:namespace App\Controllers;

use CodeIgniter\RESTful\ResourceController;
use Codeigniter\API\ResponseTrait;


class APIFolder extends ResourceController
{
    use ResponseTrait;

    protected $request;

    protected $modelName = 'App\Models\FolderModel';
    protected $format    = 'json';
    /**
    * Return an array of resource objects, themselves in array format
    *
    * @return mixed
    */
    public function index()
    {
        //
        return $this->respond($this->model->findAll(), 200);
    }

    /**
    * Return the properties of a resource object
    *
    * @return mixed
    */
    public function show($id = null)
    {
        //
        $data = $this->model->find($id);
        if (is_null($data)) {
            return $this->fail(['error' => 'Folder does not exist'], 404);
        }
        return $this->respond($data, 200);
    }

    /**
    * Return a new resource object, with default properties
    *
    * @return mixed
    */
    public function new()
    {
        //
    }

    /**
    * Create a new resource object, from "posted" parameters
    *
    * @return mixed
    */
    public function create()
    {
        //

        $data = [
            'id_folder' => $this->request->getPost('idfolder'),
            'parent_id' => $this->request->getPost('idparent'),
            'folder_name' => $this->request->getPost('foldername'),
        ];

        if ($this->model->insert($data) === false) {

            $response = [
                'errors' => $this->model->errors(),
                'message' => 'Invalid Inputs'
            ];

            return $this->fail($response, 409);
        }

        return $this->respond(['message' => 'Created Successfully'], 201);
    }

    /**
    * Return the editable properties of a resource object
    *
    * @return mixed
    */
    public function edit($id = null)
    {
        //
    }

    /**
    * Add or update a model resource, from "posted" properties
    *
    * @return mixed
    */
    public function update($id = null)
    {
        $d = $this->request->getRawInput();
        //
        $data = [
            'parent_id' => $d['idparent'],
            'folder_name'  => $d['foldername'],
            'doc_path'  => $d['docpath'],
        ];


        if ($this->model->where('id_folder', $id)->set($data)->update() === false) {
            $response = [
                'errors'  => $this->model->errors(),
                'message' => 'Invalid Inputs',
                'data'    => $data
            ];
            return $this->fail($response, 409);
        }
        return $this->respond(['message' => 'Updated Successfully',], 200);
    }

    /**
    * Delete the designated resource object from the model
    *
    * @return mixed
    */
    public function delete($id = null)
    {
        //
        $this->model->delete($id);
        return $this->respond(['message' => 'Deleted Successfully',], 200);
    }
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB