Controller not found

I am trying to develop a Plugin, with overriden class. The problem seems to be simple, but I am missing something.

Is it correct to override class in Plugin.php?:

public function getClasses()
{
 return array('plugins\CommentActions\Controller' => array('CommentActionsController'));
}

CommentActionsController.php:

class CommentActionsController extends CommentController
{

I get:

Internal Error: Controller not found

Could you share your whole CommentActionsController.php and Plugin.php file?

1 Like
<?php

namespace Kanboard\Plugin\CommentActions;

use Kanboard\Core\Filter\LexerBuilder;
use Kanboard\Core\Plugin\Base;
use Kanboard\Core\Security\Role;
use Kanboard\Core\Translator;

class Plugin extends Base
{
public function initialize()
{
    $this->template->hook->attach("template:config:sidebar",
        "CommentActions:config/sidebar");
    $this->route->addRoute('settings/commentactions', 'CommentActionsSettingsController', 'index',
        'CommentActions');
    $this->template->setTemplateOverride('task_comments/create', 'CommentActions:task_comments/create');

}

public function onStartup()
{
}

public function getClasses()
{
 return array('plugins\CommentActions\Controller' => array('CommentActionsController'));
}

public function getPluginName()
{
    return 'CommentActions';
}

CommentActionsController.php

<?php


namespace Kanboard\Plugin\CommentActions\Controller;


use Kanboard\Controller\CommentController;
use Kanboard\Core\Controller\AccessForbiddenException;
use Kanboard\Core\Controller\PageNotFoundException;
use Kanboard\Model\ConfigModel;

class CommentActionsController extends CommentController
{

/**
 * Add comment form
 *
 * @access public
 * @param array $values
 * @param array $errors
 * @throws AccessForbiddenException
 * @throws PageNotFoundException
 */
public function create(array $values = array(), array $errors = array())
{
    $project = $this->getProject();
    $task = $this->getTask();
    $values['project_id'] = $task['project_id'];
    $this->response->html($this->helper->layout->task('task_comments/create', array(
        'values' => $values,
        'errors' => $errors,
        'task' => $task,
        'project' => $project,
        'comment_actions_enabled' => $this->isCommentActionsEnabled()
    )));
}

/**
 * Add a comment
 *
 * @access public
 */
public function save()
{
    $task = $this->getTask();
    $values = $this->request->getValues();
    $values['task_id'] = $task['id'];
    $values['user_id'] = $this->userSession->getId();
    $actionPluginEnabled = $this->isCommentActionsEnabled();


    $actionsEnabled = isset($values['assign_issue']) && $values['assign_issue'];
    if( $actionPluginEnabled && $actionsEnabled ) {
     //            do something
    }


    list($valid, $errors) = $this->commentValidator->validateCreation($values);

    if ($valid) {
        if ($this->commentModel->create($values) !== false) {
            $this->flash->success(t('Comment added successfully.'));
        } else {
            $this->flash->failure(t('Unable to create your comment.'));
        }

        $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments'), true);
    } else {
        $this->create($values, $errors);
    }
}

protected function isCommentActionsEnabled() {
    return $this->configModel->getOption('comment_actions');
}

}

did I initialize controller correct or not ? someone?

should be like the CommentActionsController namespace:

return array('Plugin\CommentActions\Controller' => array('CommentActionsController'));
1 Like

sure, I’ve noticed that after I’ve posted this comment here. I’ve changed to Plugin… but it didn’t do the trick- Still no plugin found. And the second one is also not found. But the class for settings page is working

  $this->route->addRoute('settings/commentactions', 'CommentActionsSettingsController', 'index',
        'CommentActions');

Bildschirmfoto%20von%202019-10-09%2014-37-01

When is the error happening?
Is it when you are accessing an url to the controller? If so, can you provide the full path being accessed?
Are you trying to override Kanboard’s CommentController with your CommentActionsController? Or CommentActionsController should be registered as a new controller, named CommentActionsController?

1 Like

When is the error happening?

by saving the comment / by posting

<form method="post"
  action="<?= $this->url->href('CommentActionsController', 'save',
      array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>"

localhost/?controller=CommentActionsController&action=save&task_id=1&project_id=1
error: Internal Error: Controller not found

Are you trying to override Kanboard’s CommentController with your CommentActionsController?

I quess, I am trying to override CommentController class with my own.

CommentActionsController should be registered as a new controller, named CommentActionsController?

Am I not registering/overriding my CommentActionsController with getClasses() as new Controller?

The problem is that your controller URL is missing your plugin name.
You should change your form url to this:

<form method="post"
  action="<?= $this->url->href('CommentActionsController', 'save',
      array('plugin' => 'CommentActions', 'task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>"

Actually, you are registering a new Controller.
The default controller, CommentController, will still be accessible. When you want to point to your new controller you have to make sure to send the “plugin” parameter with your plugin name along with the controller name

1 Like

Then your URL will look like this:
localhost/?plugin=CommentActions&controller=CommentActionsController&action=save&task_id=1&project_id=1

1 Like

Strange, I tried also inserting ‘plugin’ => ‘CommentActions’ but to the end of array, like this:

<form method="post"
 action="<?= $this->url->href('CommentActionsController', 'save',
  array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'plugin' => 'CommentActions')) ?>"the 

page was just freezing.

Did , how you wrote and the URL is such:

localhost/?controller=CommentActionsController&action=save&plugin=CommentActions&task_id=1&project_id=1

plugin name goes after save action. But I think it is not important.
Thank you very much, I’ve struggled over this blocker for allmost 2 days. Now I have other bugs, but that will be in another story ))

The order of the params and the order of the elements inside the array should not matter

1 Like

good to know.
Thank you once more for your time and help )

1 Like