Page 1 of 1

Array Problem

Posted: Mon Nov 22, 2010 4:17 pm
by edawg13
I use Popshops Datafeed API and cant figure out an issue im having with an array. I'm trying to retrieve a category name from an array for the current page.

Here is the array code which is in the index.php file.

Code: Select all

$categories = array();
  $categories[] = array( 'name' => 'page name', 
                         'search_options' => array( 'keywords' => 'page keyword' ) );
  $categories[] = array( 'name' => 'page name', 
                         'search_options' => array( 'keywords' => 'page keyword' ) );
  $categories[] = array( 'name' => 'page name', 
                         'search_options' => array( 'keywords' => 'page keyword' ) );
This is how the script calls the current page keyword.

Code: Select all

<?php echo ucwords($_REQUEST[$popshops->nameSpace.'keywords']) ?>


The code above works fine, so I thought all I had to do was change the 'keywords' to 'name' to get what I was looking for. But that does not seem to work?

Code: Select all

<?php echo ucwords($_REQUEST[$popshops->nameSpace.'name']) ?> 
I've tried as much as my limited php knowledge can take me, so now I need some advice.

Here is the function in the popshops.php file they use to pull the page name out for the links in the navigation, but I just want to know how to retrieve just the category name for the current page, nothing else.

Code: Select all

function customCategoryLink($category) {
    $url = $this->baseURL($this->params);
    
    if (isset($category['search_options']) && sizeOf($category['search_options']) > 0) {
      foreach($category['search_options'] as $key => $value) {
        $url = $this->addParameter($url,$key,$value);
      }      
    } else {
      $url = $this->addParameter($url,'keywords',$category['name']);
    }
    $url = str_replace('?&','?',$url);
    return '<a href="'.$url.'">'.$category['name'].'</a>';
  }
Any ideas?

Re: Array Problem

Posted: Tue Nov 23, 2010 1:19 pm
by edawg13
Here are a couple of neighboring functions that may help?

BaseURL function.

Code: Select all

function baseURL($paramNamesToStrip) {
    $url = $this->requestURI();        
    foreach ($_REQUEST as $key => $value) {
      foreach ($paramNamesToStrip as $paramName) {
        $url = $this->stripParameter($url,$paramName,$key,$value);
      }      
    }        
    return $url;
  }  

AddParameter Function.

Code: Select all

function addParameter($url,$paramName,$paramValue) {
    if (strlen($paramValue) > 0) {
      $delimiter = (strpos($url,'?') > -1) ? '&' : '?';    
      $url = $url.$delimiter.$this->nameSpace.$paramName.'='.urlencode($paramValue);
    }
    return $url;
  }

Re: Array Problem

Posted: Tue Nov 23, 2010 2:43 pm
by s992
What do you get when you change 'keywords' to 'name'?

Re: Array Problem

Posted: Tue Nov 23, 2010 4:05 pm
by edawg13
Nothing. If I change keywords to name then refresh the page, I do not see anything.

Re: Array Problem

Posted: Tue Nov 23, 2010 10:49 pm
by s992
Well, the issue is likely that you are trying to access a variable that doesn't exist. $_REQUEST contains the contents for $_POST, $_GET, and $_COOKIE. So, if you don't have an array key with the value of $popshops->nameSpace.'name' being passed to via post, get, or a cookie, there will be nothing to echo.

On that page, print_r($_REQUEST) and let me know what you see.