Page Selectors in custom blocks

I have been working with Concrete5 for a few months now and I am learning something new every day. I have a piece of client work due very soon and I can't get my head around the page_selector helper.

This block is building a button. I have it doing everything that I need it to do save for one thing. I have a radio button that will deliver [via jQuery] the option to input an external url or select a page from the page selector.

The problem is is that I can't seem to capture the returned value from the page_selector helper.

I can query the radio buttons to deduce whether an internal link or external link has been selected but I need a variable with the url string to echo.

Here's my code... All that I have in controller.php is a save and a delete...

<h2>Button details</h2>
   echo $form->label('btnCaption', 'Caption');
   echo $form->text('btnCaption', array('style' => 'width: 300px'));
<h2>Internal/External Link?</h2>
   echo $form->radio('btnDest', 'btnInt');
   echo 'Internal';
   echo $form->radio('btnDest', 'btnExt');
   echo 'External';
<div id="intMenu" class="btnDestMenu">
    $formHelp = Loader::helper('form/page_selector');

   defined('C5_EXECUTE') or die(_("Access Denied."));
    <a href="<?php echo $bntDest; ?>"class="cta <?php echo $btnType;?> <?php echo $btnColour;?>">
      <div class="a">
            <div class="b">
                <?php echo $btnCaption;?>

View Replies:
hereNT replied on at Permalink Reply
For one, it looks like the value for the link will be $btnDest, which will not be the link. You need to change that $btnExternal or $btnInternal, depending.

What does the save and view methods in your controller look like?
shooftie replied on at Permalink Reply
Thanks for your speedy replay...

Here they are;

function save($args){

function view(){
         if($btnDest == 'btnInt'){
            $btnDest = $btnInternal;
         }elseif($btnDest == 'btnExt'){
            $btnDest = $btnExternal;

function delete(){
         $db = Loader::db();
         $db->Execute('delete from btButton where bID='.$this->bID);
shooftie replied on at Permalink Reply
Sorry, just to clarify, originally I did not have any output from the controller because of a badly constructed view() method. Now however, I have it working.

The question now is, how do I convert the cID number into a URL?
tbcrowe replied on at Permalink Reply
This code will get you an URL:
$page = Page::getByID($cID);
$url = DIR_REL . '/' . $page->getCollectionPath();

You can also include BASE_URL before DIR_REL if you want a fully qualified URL.
shooftie replied on at Permalink Reply
Thanks a lot for your help... unfortunately, this isn't working... the URL that it outputs looks sound enough but I keep getting a 404 [which reminds me, I need to design this as well].

I have looked through the helpers and although I am actually holding my head above water, I'm slowly sinking into a PHP swamp. I have tried picking apart some default blocks [form etc] to find the functionality in there, but no luck...

This block has changed a little since I last posted so here is the new view():

function view(){
         $dir = $this->urlDirection;
         switch ($dir){
            case 'int':
               $cID = $this->urlInternal;
               $page = Page::getByID($cID);
               $url = DIR_REL.$page->getCollectionPath();
            case 'ext':
               $url = $this->urlExternal;
         $this->set('btnUrl', $url);
shooftie replied on at Permalink Reply
I have worked it out...

THe script that you offered does almost exactly the job except for the fact that my URLs have index.php in;

staging/mysite/index.php/about [for example]...

I simply added this just before I call getCollectionPath();

$page = Page::getByID($cID);
               $url = DIR_REL.'/index.php'.$page->getCollectionPath();

and it works... I'm going to post the full code below for anyone that arrives in this thread for help. If you see anything that could/should be changed for better functionality, I welcome you suggestions.

Thanks a lot for your help... It's a massive help to know that there's an answer somewhere...
chrismodlao replied on at Permalink Reply

Is there any chance to get your full code to start devloping from this source on my own ?