Solved,
I found how to build the url.
This should do the job:
`
$targeturl=Router::url(‘/’, true).strtolower($this->request->getParam(‘prefix’));
`
Hello,
I’m trying to integrate a live search with clickable search results into my app using Ajax.
I followed the example from w3schools (https://www.w3schools.com/php/php_ajax_livesearch.asp).
The search works, but I have problems displaying the search results.
I have this line of code to build the search result:
$hint='<a href="/terms/view/'. $term->id.'"' . 'class="button" target="_blank">'.$term->name.'</a>';
This line produces a link to
> "localhost/terms/view/2"
What I need is a link to "localhost/termbase/customer/user/terms/view/2"
“Customer” and “User” are prefixes
I hope i could explain what I try to do… and anyone can give me a hint.
Here is the full code from the controller
> public function searchterm() {
> $this->autoRender=false;
> //get the q parameter from URL
> $q=$_GET["q"];
>
> //lookup all links from the xml file if length of q>0
> if (strlen($q)>0) {
> $hint="";
> $query=$this->Terms->find()
> ->select(['id','name'])
> ->contain(['Concepts'])
> ->where(['terms.name like'=>'%'.$q.'%','concepts.customer_id'=>$this->request->getAttribute('identity')->customer_id])
> ->order(['Terms.name'=>'ASC'])
> ->limit(10);
> if ($query->count() > 0) {
>
> foreach ($query as $term) {
> $y=$term->name;
> $z=$term->id;
> //echo $this->Html->link($term->name,['controller' => 'Terms', 'action' => 'view',$term->id, '_full' => true]);
> if ($hint=="") {
> $hint='<a href="/terms/view/'. $term->id.'"' . 'class="button" target="_blank">'.$term->name.'</a>';
>
> } else {
> $hint=$hint . "<br /><a href='" .
> $z .
> "' target='_blank'>" .
> $y . "</a>";
> }
> }
> }
> if ($hint=="") {
> $response=__('No Results');
> } else {
> $response=$hint;
> }
> //output the response
> echo $response;
>
> }
> }