need to add outside URL link within array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevinwinters
Forum Newbie
Posts: 20
Joined: Wed Jan 06, 2010 8:31 pm

need to add outside URL link within array

Post by kevinwinters »

I am working on a site that uses smarty templates and the owner has asked that part of the left navigation menu contain a link to a page that is not on their site, now the following code is the start of their naivation and contains links that are inside their site (like "inventory.php")

I tried to add the "Test Blog" link into the array but it comes out in the menu like "http://home site/http://test.hubspot.com...."

Is there a way I can display a link that is not inside their site within this array?

Code: Select all

<?php
$aMenu = array(
	'Home'=>'index.php',
	'View Inventory'=>'inventory.php',
      'Test Blog'=>'http://test.hubspot.com/CMS/UI/Modules/BizBlogger/4903fb476cf3'

	);
foreach($aMenu as $page=>$url):
	echo '<div><a href="'.$GLOBALS['cfg']['paths']['rel'].$url.'"';
	if($url==basename($_SERVER['PHP_SELF']))
		echo ' class="menuon"';
	echo '>'.$page.'</a>';
	echo '</div>';
endforeach;
...

Thanks for any direction on this
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: need to add outside URL link within array

Post by roders »

The problem here is the that everylink that you will put will come out as http://home site/http://test.hubspot.com. My suggestion is append your link name with an identifier
for example try this.

Code: Select all

$aMenu = array(
   'LNKHome'=>'index.php',
   'LNKView Inventory'=>'inventory.php',
      'URLTest Blog'=>'http://test.hubspot.com/CMS/UI/Modules/BizBlogger/4903fb476cf3'

   );
foreach($aMenu as $page=>$url):
    switch (substr($page,0,3))
	{
		case("LNK"):
			$link=$GLOBALS['cfg']['paths']['rel'];
		break;
		case("URL"):
			$link=$url;
		break;
		default:
			$link=$GLOBALS['cfg']['paths']['rel'];
		break;
	}
	
   echo '<div><a href="'.$link.'"';
   if($url==basename($_SERVER['PHP_SELF']))
      echo ' class="menuon"';
   echo '>'.$page.'</a>';
   echo '</div>';
endforeach;
See how i've append LNK (Internal link) URL (Url link). try and let me know how it worked.
kevinwinters
Forum Newbie
Posts: 20
Joined: Wed Jan 06, 2010 8:31 pm

Re: need to add outside URL link within array

Post by kevinwinters »

Seems very close to what I was looking for, thank you, only things were
(1) names displayed had the "LNK" and "URL" prefixes on them in the menu
(2) the inventory link and the home link linked simply to the main page ie inventory did not point to http://mainpage/inventory.php, just to http://mainpage

The url page pointed exactly how I needed it
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: need to add outside URL link within array

Post by roders »

Ok done this should definitely work now.

Code: Select all

$aMenu = array(
   'LNKHome'=>'index.php',
   'LNKView Inventory'=>'inventory.php',
      'URLTest Blog'=>'http://test.hubspot.com/CMS/UI/Modules/BizBlogger/4903fb476cf3'

   );
foreach($aMenu as $page=>$url):
    switch (substr($page,0,3))
        {
                case("LNK"):
                        $link=$GLOBALS['cfg']['paths']['rel'].$url;
                break;
                case("URL"):
                        $link=$url;
                break;
                default:
                        $link=$GLOBALS['cfg']['paths']['rel'].$url;
                break;
        }
       
   echo '<div><a href="'.$link.'"';
   if($url==basename($_SERVER['PHP_SELF']))
      echo ' class="menuon"';
   echo '>'.substr($page,3).'</a>';
   echo '</div>';
endforeach;
 
kevinwinters
Forum Newbie
Posts: 20
Joined: Wed Jan 06, 2010 8:31 pm

Re: need to add outside URL link within array

Post by kevinwinters »

Thank you roders.
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: need to add outside URL link within array

Post by roders »

You're welcome mate.
Post Reply