Re: Re: [SMARTY] dyamic include file variable
| From: | Monte Ohrt | Date: | Thu, 09 Jan 2003 15:56:21 +0000 |
| Subject: | Re: Re: [SMARTY] dyamic include file variable | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7082@lists.php.net to get a copy of this message | ||
Not that this is strictly Smarty related, but it is indirectly related
since it affects how you would setup and manage Smarty.
It is definately a personal preference issue. For instance, we use one
script. We basically have one script for frontends and one for backends,
such as index.php and admin.php.
index.php is just basically a big switch statement, loading libraries
and such where necessary. In our experience, it is easier to manage this
from one place instead of separate scripts. This way if you want to make
a global change, you do it in one place.
simplified example:
index.php
---------
// stuff like session initialization
require 'global_setup.php';
switch($_REQUEST['FROMPAGE']) {
case 'main_menu':
switch($_REQUEST['button_submit']) {
case 'edit_article':
include 'article.lib';
display_article_form(get_article_content($_GET['id']));
break;
case 'add_article':
include 'article.lib';
display_article_form();
break;
default:
...
}
case ...
default:
include 'main_menu.lib';
display_main_menu();
break;
}
Each part of the application is broken down into library files, and
functions therein handle each possible action. We try to keep
application logic out of this first page, making it only a "director",
basically including appropriate libs and sending the app off to where it
needs to go. It also makes the templates easy to administer, since every
form always has the same action:
<form method=post action="index.php">
<input type=text name="headline" value="{$headline|escape}">
... bunch more form elements ...
<input type=hidden name=FROMPAGE value="article_form">
<input type=submit name="submit_button" value="Add Article">
<input type=submit name="submit_button" value="Delete Article">
<input type=submit name="submit_button" value="Cancel">
</form>
Every form has at least a FROMPAGE (as do links) so the index.php knows
what to do.
Monte
On Wed, 2003-01-08 at 18:51, Rasmus Schultz wrote:
> <OFFTOPIC>
>
> >Oh! Well don't I feel dumb. Expesially when I had just figured out not to
> >put config variables in curlies when they were already enclosed...
> >({$title|default:#pageTitle#}).
> >
> >You would suggest a different php script for each part of the webpage? As
> >in, index.php, /users/user.php, /news/news.php, ect? I was sort of liking
> >the 'never leave index' stype, I remember having a look at some Java-style
> >MVC and it did go like that (everything from one controller), however in
> >that case it also ended up having URLs like site.com/control/news and
> >site.com/control/user, which made it look like it was accessing directories
> >when it really wasn't. Hmm. Also if memory serves doesn't phpShop run like
> >this as well? Not that it matters I suppose. What sort of issues do you
> >envision me having? If this is offtopic for the list I'm sorry. I'm just
> >starting the project and I don't want to get off on the wrong foot :) (I
> >evaluated all sorts of TEs for PHP and I have to say I think Smarty is the
> >best, no contest!).
>
> it's a matter of personal preference, and of the requirements for
> your site. for something like a PHP shop, of course it's a good
> idea, since having only one script makes it pretty easy to
> integrate with your own site.
>
> but apart from the problems with proxies and client caches, as
> mentioned, there are two reasons I never do this:
>
> first, it's disorganized - you get only one level of organization,
> like for example:
>
> site.com/index.php
> site.com/user/login.php
> site.com/user/logout.php
> site.com/user/upload.php
> site.com/news/view.php
> site.com/news/post.php
>
> here, you have the opportunity to organize your pages in folders.
> with a single index.php to display them all, you'd have something
> like:
>
> site.com/index.php
> site.com/index.php?page=userlogin
> site.com/index.php?page=userlogout
> site.com/index.php?page=userupload
> site.com/index.php?page=newsview
> site.com/index.php?page=newspost
>
> so instead of being able to organize your scripts into a user and
> news folder, for example, you now have it all in one pile.
>
> secondly, it can be pretty ineffective ... for example, you have
> maybe some database scripts in an include - now instead of simply
> including this database script in the pages that need it, you now
> need to CHECK first if they're needed, and then conditionally
> include the necessary support scripts - or worse, load your
> database script every time, even when it's not needed ... either
> way, the load of each indidual page will grow with the addition
> of every library include file. bad, bad, bad.
>
> and finally - look at those URLs, with the questionmarks and
> stuff ... let's face it, apart from the fact that they make it
> impossible for the user to write down a bookmark for a friend,
> much less learn it by heart, they're just not PRETTY! ;)
>
> </OFFTOPIC>
>
--
Monte Ohrt <monte@ispi.net>