Re: [SMARTY-DEV] ideas for the smarty class file
| From: | Monte Ohrt | Date: | Thu, 20 Feb 2003 18:50:50 +0000 |
| Subject: | Re: [SMARTY-DEV] ideas for the smarty class file | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-779@lists.php.net to get a copy of this message | ||
Thanks for the feedback, and your very welcome from all of us here :-)
Now some comments...
On Thu, 2003-02-20 at 12:11, Dennis Gearon wrote:
> FIRST OF ALL, I want to preface the ideas/comments below with:
>
> 'great job all of you!'
>
> I have begun using it and it is a fantastic piece of software. It sets the trend for years to
> come for this kind of purpose. I believe that is will become a major building block for
> additional PHP projects, more so than it is now. THANK YOU, ALL OF YOU for building this.
>
> -------------------------------------------------------------------
>
> Now to some input/suggestions on the smarty.class.php file .....
>
> -------------------------------------------------------------------
>
>
> 1/ add comments to the line:
>
> define('DIR_SEP', DIRECTORY_SEPARATOR);
>
> to explain whether this is the:
>
> '/'vs '\' situation, or the
> ':' vs ';' situation
> what the purpose of this definition is,
> where DIRECTORY_SEPARATOR is to come from,
> or what to use it for?
It is the '/' vs '\' issue.
>
> 2/ In order to make starting up for us beginning users much easier, I propose these additional
> changes:
>
> A/ Put the following definitions below the define line above in the smarty class
> definition. (as far as these names go, see comments at bottom )
>
> define('SMARTY_DEFAULT_TEMPLATE_DIR', "templates");
> define('SMARTY_DEFAULT_COMPILE_DIR', "templates_c");
> define('SMARTY_DEFAULT_CONFIG_DIR', "configs");
> define('SMARTY_DEFAULT_CACHE_DIR', "cache");
> define('SMARTY_DEFAULT_PLUGINS_DIR', "plugins");
> define('SMARTY_DEFAULT_DEBUG_TPL', "debug_tpl");
Smarty should be setup so the library files are in a library directory
(SMARTY_DIR), and application files are located local to the given
application. templates, templates_c, configs and cache are
application-specific directories, and should not generally be located
within the SMARTY_DIR. plugins is a library directory, and will be
looked for in SMARTY_DIR.
By default, Smarty looks for templates, templates_c, configs and cache
in the current working directory of the executing script, NOT the
SMARTY_DIR directory.
So, we can't look for these directories under SMARTY_DIR by default, it
will break existing installations that expect to find them in the cwd.
I know that the distribution has these all in one place, we'll make some
adjustments to it to make things more clear by moving library files
under a subdirectory.
>
> B/ Put the following lines at the top of the smarty constructor:
> ( manually wrapped to appear better in a mail client )
>
> if( !isset($this->template_dir )) $this->template_dir =
> SMARTY_DIR . SMARTY_DEFAULT_TEMPLATE_DIR;
>
> if( !isset($this->compile_dir )) $this->compile_dir =
> SMARTY_DIR . SMARTY_DEFAULT_COMPILE_DIR;
>
> if( !isset($this->config_dir )) $this->config_dir =
> SMARTY_DIR . SMARTY_DEFAULT_CONFIG_DIR;
>
> if( !isset($this->cache_dir )) $this->cache_dir =
> SMARTY_DIR . SMARTY_DEFAULT_CACHE_DIR;
>
> if( !isset($this->plugins_dir )) $this->plugins_dir =
> array(SMARTY_DIR . SMARTY_DEFAULT_PLUGINS_DIR);
>
> if( !isset($this->debug_tpl )) $this->debug_tpl =
> SMARTY_DIR . SMARTY_DEFAULT_DEBUG_TPL;
>
> C/ Change the values of the class variables in the class defintion
> to unset/nothing as per:
>
> var $template_dir;
> var $compile_dir;
> var $config_dir;
> var $cache_dir;
> var $plugins_dir;
> var $debug_tpl;
>
> 3/ Items 2A - 2C above, will cover the following circumstances;
>
> A/ If the class is used raw, and not extended,
> then the values will come out the same as they do now,
> with one exception, the value $debug_tpl. I COULD USE SOME
> IDEAS ON THIS ONE. Why is there a debug.tpl in the smarty
> distribution, but it's not referenced?
>
Normally all template files reside in the templates directory, but the
debug.tpl file is a template that is a special case. It needs to be
common to all applictions, so it also resides in the SMARTY_DIR by
default. If you set $debug_tpl to just 'debug.tpl', then it needs to be
in each template_dir for each application.
> B/ if the class is extended and the constructor for the extended
> class assigns values to the above six variables, they
> will be left alone when the child constructor then calls
> the parent constructor in the smarty class.
>
> C/ any code that now assigns the variables through
> $smarty_object_name->var_name = var_value will still overwrite
> the values in the class variables.
>
> D/ us newbies or even those wishing to have very flexible code, set the
> constant, 'SMARTY_DIR', as per the directions and tutorials, and
> all the correct files and directories can be reached. MUCH fewer,
> 'help me, I get such and such error upon new installation'
> emails as a result, and a MUCH better first impression of Smarty
> also. As it is 'SMARTY_DIR' has very little usage, except for
> having to write it in manually all over the place.
I'm all for making things easier, but we don't want to break anything
either. Smarty does need a nice installation script, and I've even seen
some things submitted in the past but I haven't had a lot of time to go
over them. Install scripts are not trivial across platforms :-)
>
> 4/ Why is debug_tpl set up to be both path and file name, instead of looking for
> it in $templates_dir ? I think if that flexibility is needed, a separate
> variable for $debug_templates should be made. Shouldn't all templates be
> in $template_dir otherwise?
>
> 5/ picyaune notes here.
>
> $template_dir is 'templates' --- SINGULAR var name, PLURAL path name
> path IS named after contents
>
> $compile_dir is 'templates_c --- SINGULAR var name, PLURAL path name
> path IS NOT named after contents
>
> $config_dir is 'configs' --- SINGULAR var name, PLURAL path name
> path IS named after contents
>
> $cache_dir is 'cache' --- SINGULAR var name, SINGULAR path name
> path IS named after contents
>
> $plugins_dir is 'plugins' --- PLURAL var name, PLURAL path name
> path IS named after contents
>
> $debug_tpl is '' --- starts out blank, but a
> default template exists
> is for both a DIRECTORY and FILE name,
> not a directory OR a file name.
>
> 6/ If changes to class vars were to be made for consistency, I would suggest the following:
>
>
> $templates_dir is 'templates' --- PLURAL var name, PLURAL path name
> path IS named after contents
>
> $templates_compiled_dir is 'templates_c'
> --- PLURAL var name, PLURAL path name
> path IS named after contents
>
> $configs_dir is 'configs' --- PLURAL var name, PLURAL path name
> path IS named after contents
>
> (THERE ARE MULTIPLE CACHE DIRECTORIES OR 'CACHES',MAKE THESE PLURAL?
> $caches_dir is 'caches' --- PLURAL var name, SINGULAR path name
> path IS named after contents
>
> $plugins_dir is 'plugins' --- PLURAL var name, PLURAL path name
> path IS named after contents
>
> $debug_tpl_file is 'debug.tpl' --- FILE NAME
It would be nice to make things consistant and perfect, but changing
property names would break stuff big time. Its the same thing with
browsers and HTTP_REFERER. It's misspelled, so fix it right? :-)
We could move to methods for setting property values, such as
set_template_dir(). That is a more proper use of object classes anyways.
Those kind of changes should be for a major release, such as 3.0 (slated
for new caching functionality)
Monte
>
> (MAYBE THIS WILL REQUIRE A SEPARATE CACHE? I DON'T THINKS SO, I'D JUST CHANGE
> THE ASSUMED LOCATION OF THE DEBUG TEMPLATE TO EITHER:
> A/ $templates_dir
> B/ or $templates_dir . 'debug'
>
> $templates_debug_dir is 'templates'
> -OR-
> $templates_debug_dir is 'templates/debug'
>
>
--
Monte Ohrt <monte@ispi.net>