Jump to content

How to escape get("")->url when echoing in href="" field


Godfrey
 Share

Recommended Posts

I'm trying to get a page url and echo it in a link, however I keep getting error:

Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in C:\wamp\www\klp\wire\core\Selectors.php line 165)

I have tried two methods:

 <a href='<?php $pages->get("gallery")->url; ?>'> Back </a>

 <?php echo ' <a href=" '.$pages->get('gallery')->url.' "> Back </a>';?> 

 
But both are getting me the same result. Sometimes half my page just doesn't even load. 
I read around and think I need to escape my quotations. I have no idea what I would escape in this case though.... I think the key problem here is the double quotes while trying to select gallery ("gallery"), because when I am doing this without having to use the get() method it works perfectly. (e.g. $page->$albumimage->url; works for me)
 
What would I escape to get this properly working?
Link to comment
Share on other sites

I don't think "gallery" is a proper selector. Either you use /gallery/ or something like template=gallery. 

$pages->get('/gallery/')->url;
$pages->find('template=gallery')->url;

Does $page->$albumimage->url really work? Shouldn't this be $page->albumimage->url?

  • Like 3
Link to comment
Share on other sites

What @arjen said + your first example doesn't really do anything:

<a href='<?php $pages->get("/gallery/")->url; ?>'> Back </a>

Second example is OK (except for the non-working selector), but what you probably meant to do in your first example was one of these:

<a href='<?php echo $pages->get("/gallery/")->url; ?>'> Back </a>
<a href='<?=$pages->get("/gallery/")->url?>'> Back </a>

(ie. you were missing an echo or short echo statement there.)

edit: fixed broken selectors to avoid confusion.. :)

Edited by teppo
  • Like 3
Link to comment
Share on other sites

@arjen and @teppo: 
 

Ohhh, didn't know about the necessary backslashes around "gallery". (I looked on the cheatsheet and the example for get() was $pages->get("selector") )

This worked!:

 <a href='<?php echo $pages->get("/gallery/")->url?>'> Back </a>



Woops, both the missing "echo" and $albumimage were silly mistakes of my when typed this question (@arjen you were right), sorry about that! 

@teppo, for some reason this wasn't working for me and broke my code:

 <a href='<?php echo $pages->get("gallery")->url?>'>


Thanks both!

Link to comment
Share on other sites

@teppo, for some reason this wasn't working for me and broke my code:

Sorry for that -- for some reason I simply copied your original (non-working) selectors and didn't fix them for my examples.. :)

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...