0

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() ?>
Rhayne
  • 1
  • 1
  • don't think it has anything to do with the plugin. Can you please post the code you use to generate the 'view' link? – arilia Apr 20 '18 at 10:24
  • Hi, thanks for your reply @arilia. Kindly look for the edited post above, related to the code of 'view' link. Do you think I've overlooked some missing snippet here? thank you so much. – Rhayne Apr 23 '18 at 07:59
  • actually I still don't see the code that generates the view link – arilia Apr 23 '18 at 10:15
  • Hi @arilia, sorry I have misunderstood your question. I have reedited my above post and added /Template/ForumThreads/index.ctp which contains the code to generate view link. thank you very much. – Rhayne Apr 24 '18 at 07:17
  • Is there a reason why you have to use a form instead of a simple link? – arilia Apr 24 '18 at 07:22
  • hi, i've used the form to record the number of views on the database each time the user clicks 'view' button. – Rhayne Apr 25 '18 at 08:06

1 Answers1

0

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']]
 ]) ?>
arilia
  • 9,373
  • 2
  • 20
  • 44
  • thank you @arilia. I will try to do as you said and inform you of result.. thank you very much =) – Rhayne Apr 24 '18 at 07:54
  • upon using = $this->Form->create($viewCounter, ['url' => ['action' => 'view', $forumThread['id'] ]]) ?>, the page is now directed to /forum-threads/view/$id but the problem is, it's not recording the number of views when clicked anymore. – Rhayne Apr 25 '18 at 08:06