Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-09-28 05:06:36

dl33
Member
Registered: 2006-06-17
Posts: 192
Website

Set textpattern variable in php

I did a bit of digging and found the following:

global $variable
$variable['something']

After which one could access a txp variable named something with value something. My question is how do I use a different value to the name?

Offline

#2 2009-09-28 05:56:05

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,320
Website Mastodon

Re: Set textpattern variable in php

variable( array('name' => 'something', 'value' => 42) );

Offline

#3 2009-09-29 11:07:09

dl33
Member
Registered: 2006-06-17
Posts: 192
Website

Re: Set textpattern variable in php

Thanks, wet. Tried your suggestions, but it throws a fatal error at me…

Fatal error: Function name must be a string in /textpattern/publish/taghandlers.php(3127) : eval()'d code on line 5

Any ideas?

Offline

#4 2009-09-29 13:13:01

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Set textpattern variable in php

What about:

global $variable;
$variable['something'] = "42";

I’m almost sure that one worked for me before.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2009-09-29 13:14:55

dl33
Member
Registered: 2006-06-17
Posts: 192
Website

Re: Set textpattern variable in php

@maniqui: Ah, misread. Yes, will also give that a try…

Found out that variable( array('name' => 'something', 'value' => 42) ); works, but it is actually a function and not a variable. I added on the $, which then created the Fatal error.

Last edited by dl33 (2009-09-29 16:21:34)

Offline

#6 2009-09-29 16:19:12

dl33
Member
Registered: 2006-06-17
Posts: 192
Website

Re: Set textpattern variable in php

variable(array('name' => 'min_wohnflaeche', 'value' => 90));
variable(array('name' => 'max_wohnflaeche', 'value' => 120));

OR

$variable['min_wohnflaeche'] = 90;
$variable['max_wohnflaeche'] = 120;

Running into a bit of trouble here. This sets the two txp variables just fine, but almost certainly as strings. Any way to make sure that they are set as integers?

Last edited by dl33 (2009-09-29 16:31:45)

Offline

#7 2009-09-29 18:47:40

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Set textpattern variable in php

dl33 wrote:

Found out that variable( array('name' => 'something', 'value' => 42) ); works, but it is actually a function and not a variable. I added on the $, which then created the Fatal error.

Ofcourse it is a function. All TXP tags are functions. If you want it to be in a string, then put it into string. This sets it (yes, it is a function):

variable(array('name' => 'something', 'value' => 42));

And this outputs it:

variable(array('name' => 'something'));
$variable['something'];

And we can also put the output results inside a string:

$mystring = variable(array('name' => 'something'));
$mystring = $variable['something'];

Running into a bit of trouble here. This sets the two txp variables just fine, but almost certainly as strings. Any way to make sure that they are set as integers?

Show us your code. Note that $variable is a global. And (int), settype(), etc. can be used to turn strings into integers and likewise.

Offline

#8 2009-09-29 18:51:05

dl33
Member
Registered: 2006-06-17
Posts: 192
Website

Re: Set textpattern variable in php

Thanks a lot for the reply Gocom, but managed to solve the problem another way: This was for use with smd_query, so setting the db field as INT instead of making sure that the txp variable was an integer made the query go through… phpmyadmin to the rescue…

Offline

Board footer

Powered by FluxBB