Jump to content

Recommended Posts

I have a class which defines the $sQuery variable as per the below:

 

class shopcore
{
var $iMerchantId;
var $iCategoryId	= 0 ;
var $iProductId;
var $sQuery;

 

later in the class, sQuery gets set as follows: 

 

$this->sQuery 		= strlen($_GET['q']) > 0 				? trim( strip_tags( urldecode($_GET['q']) ) ) 	: null;

 

This whole class gets included in a file, let's call it sony-laptop.php.  Thing is, I want to manually set $sQuery to have a value of "sony laptop".  I don't want to use the querystring q to set this, I just want to manually define another variable in my sony-laptop.php file, lets called it $KeyphrasePage, and then set $sQuery to this. 

 

I've tried stuff like this: 

 

Early in sony-laptop.php file, define the first variable:

 

$KeyphrasePage = "sony laptop";

 

Then within class try and set sQuery to this:

 

$this->sQuery = $KeyphrasePage;

 

but it's not getting set at all, it seems $KeyphrasePage isn't passed into the class.  :'( So how to I pass my $KeyphrasePage into the class properly and then set sQuery to it???

 

Any help much appreciated.

 

Thanks

In your shopCore class file, put the following:

 

    function set_sQuery($yourVariable){

            $this->sQuery= $yourVariable;

        }

 

Then, in sony-laptop.php you can set the value by:

$KeyphrasePage = 'sony laptop';

$shopCore->set_sQuery($KeyphrasePage);

Also, you might add the following to your shopCore class file:

 

function get_sQuery(){

          return $this->sQuery;

}

 

Then in sony-laptop.php you can use:

 

$shopCore->get_sQuery;

 

to get the current value of $sQuery;

Thanks for your reply.  I still haven't quite got it working. 

 

The class, which is being included in the master file, sony-laptop.php, is:

 

class shopcore
{
var $sQuery;

 

Then within this is the function: 

 

public function gatherEnvData()

 

Which contains:

 

if ( strlen($_GET['q']) > 0 ) {
	$this->sQuery 		= strlen($_GET['q']) > 0 				? trim( strip_tags( urldecode($_GET['q']) ) ) 	: null; 
	}
	else {
	$this->sQuery = $KeyphrasePage;

 

I'm still not managing to set sQuery, have I got the lines in the original file wrong?  In original file I have:

 

$KeyphrasePage = "sony";
$gatherEnvData->set_sQuery($KeyphrasePage);

 

 

Thanks

 

 

 

 

 

Your code doesn't make sense to me.

 

I think urldencode should be urlencode though.

 

Edit: my mistake, you're right. urldencode is correct (the opposite of urlencode!!).

 

Do you have the set_sQuery method defined? Also, are you sure sQuery isn't an empty value (rather than not being set)?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.