Re: HTML_Template_Flexy private vars in controller
| From: | Didier Galland | Date: | Fri, 04 Jul 2003 23:13:17 +0000 |
| Subject: | Re: HTML_Template_Flexy private vars in controller | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-6490@lists.php.net to get a copy of this message | ||
I'll try to be more clear (my english is not very good). The goal is to
hide internal stuff from outside (esp. designers) : private vars are
impossible to output, phpdocumenter won't parse them, flexy will ignore
them, etc.
You ask me for an example :
I've wrote this method in my parent class controller :
function set_tags($object)//param $object is a data object
{
foreach(get_object_vars($this) as $tag_name => $default_value) {
if (!is_array($this->$tag_name)) {
$tag_value = $object->get($tag_name);
if (!empty($tag_value)) {
$this->$tag_name = $tag_value;
} elseif (!empty($default_value)) {
$this->$tag_name = $default_value;//value in declaration
of var
}
} elseif (is_array($this->$tag_name) &&
method_exists($this,'set_' . $tag_name)) {
//used for lists of other objects, $products in a category
page e.g.
$method = 'set_' . $tag_name;//name of the method that set
the array of objects
$this->$method($object->get('id'));
}
}
}
So, in sub-classes controller (in the constructor), I call
$this->set_vars($_page_object) and all my declared vars are set
automatically.
The downside of this is that even $vars that are not intended to be output
($_template, $_modulename of sub-controller, etc.) are set by this method.
Indeed, get_object_vars considers all vars, included private ones, useless
parsing can then occurs. So if private vars are ignored by flexy, I save
some parsing (?? I'm not sure, and I don't know performance effects).
btw:
{t:r} triggers a
"Warning: htmlspecialchars() expects parameter 1 to be string, object given"
Regards,
Didier
"Alan Knowles" <alan@akbkhome.com> a écrit dans le message de news:
3F02278E.5020402@akbkhome.com...
> Didier Galland wrote:
> > Is Flexy skipping private vars in the controller and doesn't output them
? I
> > mean vars that begins by an underscore. So if $_test in the controller
and
> > {_test} in the template, {_test} is outputed without modification
({test}
> > from $test is outputed normally).
> >
> > I would like to know if this is an intended feature
> It was.
> and if this feature will
> > remains in future versions of flexy.
> I'm open to ideas on this.
>
> It is (would be ?) a nice feature, when
> > setting vars to output automatically (with get_object_vars($this) e.g.),
> the old version did do something like that, if you have not disabled php
> in code, at present you can do
> <script language="php">
> print_r($t);
> </script>
>
> from what I remember, I did add it as a modifier in early versions -
> eg:
> {t:r}
> but have no made any decisisons on modifiers for the current version.
>
>
> > also providing a mean to set a nice api / doc for designers (hiding
private
> > vars).
> Not quite sure what you are getting at here - have you got an example?
>
> Regards
> Alan
> >
> > Regards,
> >
> > Didier
> >
> >
>