CakePHP3 - FriendsOfCake Search Plugin Form Link Not Working

158 views Asked by At

CAKEPHP 3.0

I have used this search plugin for the Help Center I am working on. https://github.com/FriendsOfCake/search

So I have already integrated this plugin on a Forum page and it can successfully filter the searched keyword accurately. However, when I click the 'view' button of the topic from the search results https://gyazo.com/b53046571a26c8dfea624b1e7aee88d7, the URL is changed to /index/?view=view&forum_thread_id=10 and can't locate its View page which is supposed to be /forum-threads/view/10

Does anyone know why this plugin changes the URL of a clicked button link? Where to check or what file should I modify so that it can successfully locate the view page? Thank you for your help in advance.

[EDIT]

Template\ForumThreads\index.ctp

<?= $this->Form->create($viewCounter) ?>
    <?= $this->Form->button('View', [
        'type' => 'submit', 
        'class'=>'btn btn-link btn-xs',
        'escape' => false, 
        'name' => 'view', 
        'value'=>'view' 
    ]) ?>
    <?= $this->Form->hidden('forum_thread_id', [
        'value' => $forumThread['id']
    ]) ?>
<?= $this->Form->end() ?>
1

There are 1 answers

2
arilia On

For some reason you are using a form to redirect to the view page

assuming this is the desired behavior (you actually want to send POST data to the view) then you have to tell the form which is the action

<?= $this->Form->create($viewCounter, ['url' => ['action' => 'view']) ?>

otherwise it will send the data to the page you are in (the index page) and then the PRG component of the search plugin transforms the POST data into GET parameters

if you don't need to send POST data you can simply create a link

<?= $this->Html->link('view', [
    'action' => 'view', 
    '?' => ['forum_thread_id' => $forumThread['id']]
 ]) ?>