Why everything works for me in the public / index.php file:

use Controller\ClientsController; $myControl = new ClientsController(); $myControl->hello(); 

and if, instead of this initialization, I connect the auxiliary file all.php, into which I insert the same lines of the class declaration:

 use Controller\ClientsController; require "../src/routes/all.php"; 

Is the class ClientsController not in it? In fact, the code of the file all.php is inserted into index.php and at the same time everything should work fine, does the path really affect this? What's the catch? Project structure:

 `-classes --ClientsController.php -public/ --index.php -src/ --routes/ ---all.php ` 
  • what exactly does not mean? - etki
  • This means: Fatal error: Class 'ClientsController' not found in C: \ xampp \ htdocs \ goodfood \ src \ routes \ all.php on line 17 - cm-brain
  • Will give the complete code, please - etki
  • You first write use Controller\ClientsController , and then require . Try swapping the strings. - Pavel Sokolov
  • The first message has all the main. Here is the contents of classes / ClientsController.php: <?php namespace Controller; class ClientsController { public function hello() { echo "Hello true class"; } } ?> <?php namespace Controller; class ClientsController { public function hello() { echo "Hello true class"; } } ?> <?php namespace Controller; class ClientsController { public function hello() { echo "Hello true class"; } } ?> - cm-brain

1 answer 1

Write the absolute path, instead of 2 points

 require "../src/routes/all.php"; 
  • All the same he writes: Fatal error: Class 'ClientsController' not found in C: \ xampp \ htdocs \ goodfood \ src \ routes \ all.php on line 17 - cm-brain
  • And yes, first require, then use - Alexandr Malyita
  • Yes, you did not understand, require... all.php connects the file in which the class ClientsController is used - cm-brain
  • If I connect it below, then this class will not be found in all.php. But the problem is that he doesn’t seem so and so - this is the main question - cm-brain
  • if instead of require in its place write: use Controller\ClientsController; require "../src/routes/all.php"; use Controller\ClientsController; require "../src/routes/all.php"; then everything will work, but how to make everything work in the included file? - cm-brain