By: halinux
Date: 2004-06-25
Time: 14:26
|
constant and exist
Hi!
I have two questions:
1.
A like to display a php variable if only it exists:
if(exist($varia)) echo $varia;
like this, until now I can only do this:
[var.varia;noerr]
and if the variable not exist, not show the error messages.
But it not to good. It would be useful at conditional display for me.
What is the solution?
2. How can I display php constants?
define("CONST", "Hello world.");
Until now, I create one variable and display this:
$const = CONST;
[var.const]
But it is plus work for nothing.
Have you any idea?
Thanks,
Adam Horvath
|
By: Skrol29
Date: 2004-06-25
Time: 14:45
|
Re: constant and exist
Hi Halinux,
1:
when you are using noerr, the field merge continue normally with the value '' (empty string).
So you can use noerr and if together.
Example:
[var.varia;noerr;if [val]='';then 'not defined']
or
[var.varia;noerr;ifempty 'not defined']
2:
Since TBS 1.96, you can build you own tag types that you marge with your own function using MergeField().
Example:
HTML: [cst.myconstant]
PHP:
$TBS->MergeField('cst','m_get_constant',true);
...
function m_get_constant($cstname) {
return constant($cstname);
}
|
By: halinux
Date: 2004-06-25
Time: 15:06
|
Re: constant and exist
You replied really fast ....:)
I learn tbs continously.
Really good thing.
Just go right on.
...............
Adam
....
.
|
By: halinux
Date: 2004-06-28
Time: 10:33
|
Re: constant and exist
Hi
It's not work for me, but it seems really simple.
hmmm.php:
<?php
if(!defined('xself') ) { define("xself", $_SERVER['PHP_SELF']); }
include_once('../tinybutstrong/tbs-class.php');
$tbs = new clsTinyButStrong;
$tbs->MergeField('cst','tbs_get_constant', 'true');
function tbs_get_constant($cstname) {
return $cstname;
}
$tbs->LoadTemplate("hmmm.html", "UTF-8");
$tbs->Show();
?>
hmmm.html:
Show constanst: [cst.xself]
There is now substitution. What goes wrong?
Thanks,
Adam
|
By: Skrol29
Date: 2004-06-28
Time: 11:09
|
Re: constant and exist
replace
$tbs->MergeField('cst','tbs_get_constant', 'true'); |
by
$tbs->MergeField('cst','tbs_get_constant', true); |
and replace
function tbs_get_constant($cstname) {
return $cstname;
} |
by
function tbs_get_constant($cstname) {
return constant($cstname);
} |
|
By: halinux
Date: 2004-06-28
Time: 12:15
|
Re: constant and exist
Aha,
the single quotes! It was the mistake.
Thanks a lot. This works.
Adam
|
By: moraes
Date: 2005-03-10
Time: 03:30
|
Re: constant and exist
Hi.
I've just started to try TBS.
I'm trying to use TBS inside a class, and then I can't just call a 'custom function' to parse a constant. How can I call a class method instead of a function?
Here's a code example:
require_once($DIR_LIBS . 'admin/tbs.php');
class ADMIN {
function ADMIN() {
global $DIR_LIBS;
$this->TBS = new clsTinyButStrong;
$this->TBS_path = $DIR_LIBS . 'admin/themes/classic/';
}
function action_login($msg = '', $passvars = 1) {
$this->TBS->LoadTemplate($this->TBS_path.'login.TBS.php');
$this->TBS->MergeField('language_file','get_constant', true);
$this->TBS->Show();
}
function get_constant($name) {
return constant($name);
}
}
|
How could I solve this?
|
By: Skrol29
Date: 2005-03-11
Time: 00:52
|
Re: constant and exist
Hi Moraes,
I'm afraid it is not yet possible to do it with TBS 2.01.
I'd like TBS to be OO friendly, and I've been thinking of how to make this feature before. But I haven't found yet how to tell the path for a method to call, using a simple string parameter.
It could be something like:
$OBJ->TBS->MergeField('cst','ClassRoot.the_method', true); |
This assumes that ClassRoot is the name of an existing class.
But this need the class to not use $this variable, because the method will be called without class instanciation.
Or it can be:
$OBJ->TBS->MergeField('cst','MyGlobVar.the_method', true); |
This assumes that $MyGlobVar is a global variable which is an instanciation of the wanted class.
If any OO developer have advices or suggestions here, they are welcome.
If there is a good solution, I can do it for the next TBS version.
|
By: moraes
Date: 2005-04-20
Time: 02:57
|
Re: constant and exist
I've just downloaded version 2.02 and will try to implement this again. :-)
moraes
|
By: moraes
Date: 2005-04-20
Time: 03:55
|
Re: constant and exist
success! :-D
class ADMIN {
function ADMIN() {
}
function login() {
$admin = new ADMIN();
$this->tpl->ObjectRef = &$admin;
$this->TBS->MergeField('language_file','~get_constant', true);
$this->TBS->Show();
}
function get_constant($name) {
return constant($name);
} |
This is working already, but I would like to know: where should I define the ObjectRef? Maybe it would be better in the constructor? Could it be done there? I'm still a bit lost. :-|
|
By: Skrol29
Date: 2005-04-20
Time: 11:05
|
Re: constant and exist
It's seems to me that it should be defined just after the property $this->TBS is defined.
|
By: moraes
Date: 2005-04-20
Time: 11:22
|
Re: constant and exist
class ADMIN {
function ADMIN() {
global $DIR_LIBS;
$this->TBS = new clsTinyButStrong;
$this->TBS_path = $DIR_LIBS . 'admin/themes/classic/';
} |
TBS is instantiated inside the class constructor (like above). I thought defining the ObjectRef inside it wouldn't work. I'm trying but I can't see a way to point ObjectRef to the class itself, without having to redefine it in every function. :-O
Below is a (obviously failed) attempt:
function ADMIN() {
global $DIR_LIBS;
$this->tpl = new clsTinyButStrong;
$this->tpl_path = $DIR_LIBS . 'admin/themes/classic/';
$admin = new ADMIN();
$this->tpl->ObjectRef = $admin;
}
|
thanks!
moraes
|
By: Skrol29
Date: 2005-04-20
Time: 11:42
|
Re: constant and exist
Yes you can, and there is no need to create a new instance:
class ADMIN {
function ADMIN() {
global $DIR_LIBS;
$this->TBS = new clsTinyButStrong;
$this->TBS_path = $DIR_LIBS . 'admin/themes/classic/';
$this->TBS->ObjectRef = &$this;
}
}
|
|
By: moraes
Date: 2005-04-20
Time: 11:47
|
Re: constant and exist
Yes, it works like a charm. Wonderful.
Thanks a lot, skrol. Now I'lll have a lot of fun! :-D
moraes
|
|
Posting in progress.
Please wait...
|