[Solved] CakePHP 3.x error about Controller missing after default project created

I’ve almost successfully installed CakePHP per your guide at https://book.cakephp.org/3.0/en/installation.html and used composer to create “myapp_test” project folder which I moved to my Apache website folder and set the group/user permissions correctly on the folder and contents (recursively) using chown.

Note, I am using ISPConfig 3.1 on CentOS 7.3. ISPConfig manages all the Vserver Host conf files, so I cannot modify them to set the DocumentRoot as it’s overwritten with any change to the GUI. I tried editing the Vhost file anyway and restarting Apache but it didn’t help matters with the issue below.

I am hitting an issue where I get an error trying to load my Cake test project via the URL. I go to myserver.local/myapp_test/webroot and get this error:

Missing Controller Cake\Routing\Exception\MissingControllerException
Error: Myapp_testController could not be found.

Thoughts? Ideas?
Here’s the Cake error log, the same error is repeating:
2017-08-09 00:23:59 Error: [Cake\Routing\Exception\MissingControllerException] Controller class Myapp_test could not be found.
Exception Attributes: array (
‘class’ => ‘Myapp_test’,
‘plugin’ => NULL,
‘prefix’ => NULL,
’_ext’ => NULL,
)
Request URL: /myapp_test/myapp_test
Stack Trace:
#0 /var/www/clients/client2/web2/web/myapp_test/webroot/index.php(36): Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
#1 {main}

I also checked the access_logs for the VHost, maybe it can help?:
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/webroot/ HTTP/1.1” 404 32737 “-” "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/debug_kit/js/toolbar.js HTTP/1.1” 304 230 “http ://mysite.local/myapp_test/webroot/” "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/debug_kit/toolbar/9a05a9ef-2653-435c-a2bd-b0b140203e99 HTTP/1.1” 200 4187 “http ://mysite.local/myapp_test/webroot/” "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/debug_kit/img/cake.icon.png HTTP/1.1” 304 231 “http ://mysite.local/myapp_test/debug_kit/toolbar/9a05a9ef-2653-435c-a2bd-b0b140203e99” "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/debug_kit/css/reset.css HTTP/1.1” 304 230 “http ://mysite.local/myapp_test/debug_kit/toolbar/9a05a9ef-2653-435c-a2bd-b0b140203e99” "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/debug_kit/css/toolbar.css HTTP/1.1” 304 231 “http ://mysite.local/myapp_test/debug_kit/toolbar/9a05a9ef-2653-435c-a2bd-b0b140203e99” "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/debug_kit/js/debug_kit.js HTTP/1.1” 304 231 “http ://mysite.local/myapp_test/debug_kit/toolbar/9a05a9ef-2653-435c-a2bd-b0b140203e99” "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/debug_kit/js/toolbar-app.js HTTP/1.1” 304 231 “http ://mysite.local/myapp_test/debug_kit/toolbar/9a05a9ef-2653-435c-a2bd-b0b140203e99” "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
172.16.0.10 - - [08/Aug/2017:19:21:52 -0400] “GET /myapp_test/debug_kit/js/jquery.js HTTP/1.1” 304 231 “http ://mysite.local/myapp_test/debug_kit/toolbar/9a05a9ef-2653-435c-a2bd-b0b140203e99” “Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko”

Thanks!

First of All, please post the SS of the error, it’s very hard to read like this.

Secondly, you MUST use CakePHP naming convention correctly. CakePHP Conventions - 3.10
every controller must have a plural name.

Navigate to this path \src\Controller and tell me the what is the file name of your Controller? Exactly.

For E.g: MyappTestController or Myapp_testComtroller?

Note this is a brand new, not modified in any way, default application skeleton and the core CakePHP library downloaded using Composer.

Error Screenshot:

ls of path src/Controller/:
[root@s4 ~]# ls -la /var/www/mysite.local/web/myapp_test/src/Controller/
total 8
drwxrwxr-x 3 web2 client2 72 Nov 7 2015 .
drwxrwxr-x 8 web2 client2 87 Nov 7 2015 …
-rw-rw-r-- 1 web2 client2 1712 Nov 7 2015 AppController.php
drwxrwxr-x 2 web2 client2 18 Nov 7 2015 Component
-rw-rw-r-- 1 web2 client2 1863 Nov 7 2015 PagesController.php
[root@s4 sites-enabled]#

Thanks!

@kyferez Answer the above question as well so that I can help you properly.

I did, it’s under the screenshot. There is no controller for myapp. Only AppController.php and PagesController.php. This is what was auto-generated by Composer.

Am I missing a step or did Composer not do something?

Alright, so you haven’t read the full documentation of cake. I will highly recommend you to learn how MVC works.

As for your problem, the error in YELLOW color tells you the solution itself.

  1. Create controller

Create a controller file in \src\Controller

Myapp_testsController.php

  1. Do the following coding in it
<?php

namespace App\Controller;

use App\Controller\AppController;

class Myapp_testsController extends AppController
{
public function index(){
echo “Hello World.!”;
}
}

  1. Create View Folder

Create your view folder here \src\Template"Your Controller name"
in our case: \src\Template\Myapp_tests

  1. Create View File

Navigate to your recently created folder i.e: \src\Template\Myapp_tests
and create a file name index.ctp

and Everything will work now.

Here are useful links:

https://book.cakephp.org/3.0/en/controllers.html
https://book.cakephp.org/3.0/en/views.html

Ok thank you, that makes sense.

The reason I was confused is that in the installation it has a section to Fire it up. No mention that it won’t yet work and a controller needs to be created. It may help others to update this with that key bit of info:

No.

If you have a database then you have to bake your models i.e database tables.

Go through these:
https://book.cakephp.org/3.0/en/tutorials-and-examples.html

Humm, those are pretty complicated examples full of terminology that seems specific to CakePHP.

Are there simpler ones that build up to that to help learn the structure and terminology? This is quite a learning curve. I’m trying to learn because I’m trying to support and modify a legacy app build on CakePHP but figuring out everything is proving difficult because I don’t understand CakePHP well. I found leaning to write a plugin for Wordpress was easier than it is for me to learn CakePHP.

It would really help to have tutorials that start with a basic Hello World, add some components like links, add a form, etc., and not use cake specific language without explaining those terms.

Here is my recommendation, it’s paid but it will worth it trust me:
https://www.lynda.com/CakePHP-tutorials/Welcome/452749/481153-4.html?autoplay=true

For free tutorials:
https://www.tutorialspoint.com/cakephp/index.htm

This one is for older version but you will get the idea

This tutorial is not great but will help you:

You can search on youtube, you might find more useful tutorials.

~ Cheers

Thanks! I also found this that seems ok so far

Alright. :slight_smile:

If you have found your solution with my answers then make sure you change the Title of you topic to
CakePHP 3.x error about Controller missing after default project created [Solved]

It will save time of those who are here to answer to people’s question.