error in directory to require in php failed error to open stream: No such file or directory

Asked

Viewed 25 times

0

Personal my application works like this: it is a task registration system with mysql connection. The system of registering the task ta working. Since I created a kind of layered system, there is a directory called private_directory that contains some other folders inside it, and one of them is the controller, in the controller is the task controller that receives the require from the Taskcontroller that is in the public directory in the controller folder. The public directory has the html classes and receives the data coming from the front, sends by require (not yet put anything by js) to the private directory where the data is processed and sent to the database.

the error ta that, the path I put in the public controller require pointing to the private controller ta ok to include tasks, but to recover a task, it from the error.

code in public Taskcontroller

  <?php


require_once '../../private_directory/controller/TaskController.php';
?>

code in private Taskcontroller

require "../../private_directory/entities/Task.php";
require "../../private_directory/services/TaskService.php";
require "../../private_directory/Connection.php";

and the deals I won’t put here

the error ta in the class all tasks, which should display all tasks that have been entered. I didn’t even get to do the bank recovery code, I just created an initial system to test if the flow was picking up, and it was with this require there, and it’s not getting.

 <?php
$action = 'recover';
require '../public_directory/controller/TaskController.php';
?>

this action is used as parameter in the negotiations to know if it is to recover the data or if it is to insert, this is programmed in the private controller.

here the error that returns

Warning: require_once(../../private_directory/controller/TaskController.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Cadastro\public_directory\controller\TaskController.php on line 5

Fatal error: require_once(): Failed opening required '../../private_directory/controller/TaskController.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Cadastro\public_directory\controller\TaskController.php on line 5

it enters the link that is on the front: . /public_directory/controller/Taskcontroller.php, but says he can’t find the way to what’s in the public controller. if I remove the .. / from ALL controllers, it works and recovers the files, however the function of Insert stops working. It is strange that for the Insert system the flow works, but for recovery does not work.

here as organized ta

inserir a descrição da imagem aqui

someone can help me in this?

1 answer

0

Follows a temporary solution (There are better), but will already solve your problem include $_SERVER['DOCUMENT_ROOT'] . '/public_directory/controller/Taskcontroller.php';

$_SERVER['DOCUMENT_ROOT'] takes the absolute path to the folder that is the index makes an echo to can analyze better and understand

echo $_SERVER['DOCUMENT_ROOT'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.