PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 13, 2022

[FIXED] cakephp3- controller could not be found

 February 13, 2022     cakephp-3.0, php     No comments   

Issue

I'm learning cakephp 3 framework. Its better to say I'm pretty much new at this.

I'm trying to make a plugin. I baked a plugin like this bin/cake bake plugin myFirstPlugin Then I baked a controller for this plugin using

bin/cake bake controller --plugin myFirstPlugin test

So inside my plugin's controller, I defined a function which does nothing other than outputting a message.

This is my plugin's controller

<?php
namespace myFirstPlugin\Controller;

use myFirstPlugin\Controller\AppController;

class testController extends AppController
{
    public function index()
    {
        $msg = 'test';
        $this->set(compact('msg'));
        $this->set('_serialize', ['msg']);
    }
}
?>

and in my application's route (not in plugin's route) I wrote this:

Router::scope('/myFirstPlugin/index', function (RouteBuilder $routes){  
    $routes->connect('/', ['controller' => 'test', 'action' => 'index']);
}); 

So, when I try to call this using the below url

http://localhost/myApplication/myFirstPlugin/index

I got this error:

Error: testController could not be found.
Error: Create the class testController below in file: src\Controller\testController.php

Why am I getting such an error even though I created a controller. Thanks!


Solution

You need to mention your plugin name within $routes->connect

Router::scope('/myFirstPlugin/index', function (RouteBuilder $routes){  
    $routes->connect('/', ['plugin' => 'myFirstPlugin','controller' => 'test', 'action' => 'index']);
}); 


Answered By - Object Manipulator
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing