Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Is this right?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Installation and Setup
View previous topic :: View next topic  
Author Message
Cornofstarchy
Smarty n00b


Joined: 12 Jun 2004
Posts: 4

PostPosted: Sat Jun 12, 2004 8:19 pm    Post subject: Is this right? Reply with quote

Hi, I installed Smarty but I'm really new to setting up webservers and such so I was wondering if someone could tell me if I did it the "right way".

(I'm using WinXP, Apache2, and PHP4.)

[ Paths ]
C:\PHP\smarty\
C:\Program Files\Apache Group\Apache2\htdocs\
C:\Windows\php.ini

1. Unzip Smarty.
2. Move the files from /smarty/lib/ into C:\PHP\smarty\
3. Edit php.ini...

Code:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2" 
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
include_path = ".;c:\PHP\includes;c:\PHP\smarty"


4. Time to test. Create a folder named /practice/ in htdocs. Move the files from /smarty/demo/ into /practice/.

5. Create a folder named /cache/ inside /practice/. /practice/ now contains 4 folders: /cache/, /templates/, /templates_c/, and /config/ as well as the test driver index.php.

6. Edit /practice/index.php so that it can read Smarty.class.php...

Code:

<?php
require 'C:\\PHP\\smarty\\Smarty.class.php';

...


7. Close everything and open index.php in the browser.

For me, this works. I get a test page and a popup window. However, the part I wasn't really sure about is am I supposed to include

Code:

<?php
require 'C:\\PHP\\smarty\\Smarty.class.php';

...


in every template that I create with a direct path to my C:\PHP\ directory? Is this safe or should I be doing this a different way?

Finally, if I ever create a new site (ie. a new folder inside /htdocs/ that uses a different template), will I also have to create the templates, templates_c, cache and config folders for the new site? Or can I just have those 4 folders in the root of /htdocs/ and pull my templates from those folders? Again, is this a good thing to do? Thanks for any help!

~Corn~
Back to top
View user's profile Send private message
Cornofstarchy
Smarty n00b


Joined: 12 Jun 2004
Posts: 4

PostPosted: Sat Jun 12, 2004 11:19 pm    Post subject: Reply with quote

Nevermind, I figured out both of my questions. Here are the answers in case someone needs them:

1. If you edited your php.ini file like I did above, then all you need is the following piece of code for every template file or whatever:

Code:

<?php
require 'Smarty.class.php';

...


You don't need to use the absolute path (c:\php\blahblah\) because it's already stated in your php.ini config file. To get the above code to work, all you have to do is to restart the Apache server.

2. It's recommended to have the 4 special directories (templates, templates_c, config, and cache) for each website folder. You don't have to but you'll probably get yourself confused along the way as to which templates go with which site. So it's better to have new folders for each site.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Jun 12, 2004 11:55 pm    Post subject: Reply with quote

Also keep those directories out of your document root if possible, or disallow browser access to them.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Jun 13, 2004 12:05 am    Post subject: Reply with quote

Cornofstarchy wrote:

2. It's recommended to have the 4 special directories (templates, templates_c, config, and cache) for each website folder. You don't have to but you'll probably get yourself confused along the way as to which templates go with which site. So it's better to have new folders for each site.


I'd word that a bit stronger and claim that you really should do this. Asides from the reason given above, it is particularly important that you don't share a single set of tempates_c and cache directories among many templates directories. This is because if within two different templates directories you have a template with the same path/name in each directory, they will result in the same path/file within the templates_c and (likely) cache directories, which is almost certainly not wanted. (Basically, it means that they would overwrite each other)


Last edited by boots on Sun Jun 13, 2004 12:08 am; edited 2 times in total
Back to top
View user's profile Send private message
Cornofstarchy
Smarty n00b


Joined: 12 Jun 2004
Posts: 4

PostPosted: Sun Jun 13, 2004 12:06 am    Post subject: Reply with quote

mohrt wrote:
... or disallow browser access to them.


This I know how. Use *.htaccess.

mohrt wrote:
Also keep those directories out of your document root...


How is that possible? You get these:

Code:

Warning: Smarty error: unable to read resource: "index.tpl" in c:\PHP\smarty\Smarty.class.php on line 1102

Fatal error: Smarty error: the $compile_dir 'templates_c' does not exist, or is not a directory. in c:\PHP\smarty\Smarty.class.php on line 1102


Don't you need those folders in the same directory as your (in this case) indextest.php?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Jun 13, 2004 12:09 am    Post subject: Reply with quote

Check this post for one example setup description on Windows with Apache. There are actually, many ways to achieve that same goal Wink
Back to top
View user's profile Send private message
Cornofstarchy
Smarty n00b


Joined: 12 Jun 2004
Posts: 4

PostPosted: Sun Jun 13, 2004 1:05 am    Post subject: Reply with quote

boots wrote:
Check this post for one example setup description on Windows with Apache. There are actually, many ways to achieve that same goal Wink


For those who are reading this, you only need to read the boostrap part where you extend the Smarty class by adding a new function.

boots wrote:
Cornofstarchy wrote:

2. It's recommended to have the 4 special directories (templates, templates_c, config, and cache) for each website folder. You don't have to but you'll probably get yourself confused along the way as to which templates go with which site. So it's better to have new folders for each site.


I'd word that a bit stronger and claim that you really should do this. Asides from the reason given above, it is particularly important that you don't share a single set of tempates_c and cache directories among many templates directories. This is because if within two different templates directories you have a template with the same path/name in each directory, they will result in the same path/file within the templates_c and (likely) cache directories, which is almost certainly not wanted. (Basically, it means that they would overwrite each other)


To achieve this, so far, I have auto_template.inc located in C:\Program Files\Apache Group\Apache2\htdocs\wvbcMain\:

Code:

<?php

define ('MY_ROOT_DIR','C:\\Program Files\\Apache Group\\Apache2\\');
define ('PROJECT_NAME','smarty_temp\\wvbc\\');

include_once 'Smarty.class.php';

class mySmarty extends Smarty
{
    function mySmarty()
    {
        $this->config_dir = MY_ROOT_DIR . PROJECT_NAME . 'configs';
        $this->template_dir = MY_ROOT_DIR . PROJECT_NAME . 'templates';
        $this->compile_dir = MY_ROOT_DIR . PROJECT_NAME . 'templates_c';
        $this->cache_dir = MY_ROOT_DIR . PROJECT_NAME . 'cache';
        $this->Smarty();
    }
}
?>


I'm using auto_template.inc as a template for other projects as well. For example, if I decide to create a new project named "ff7", then I would copy the smarty_template.inc file (above) and change the PROJECT_NAME constant. I would also create a new folder within /smarty_temp/ like so: C:\Program Files\Apache Group\Apache2\smarty_temp\ff7\. Within /ff7/ of /smarty_temp/, I would have the 4 special folders: templates, templates_c, cache, and config.

This works but is tedious especially when you have many many projects. Is there a workaround this? I'm currently thinking of passing PROJECT_NAME to auto_template.inc then including it but that only takes care of the first part, not the new folders part. Not to mention that I might not be able to easily pass the constant to the .inc file. Or maybe I should write an install script of some sort that will allow you to enter the value for PROJECT_NAME and the script will automatically create the appropriate folders/files? It doesn't seem like this idea would work on a pay server. Other people who don't host their own sites might not be able to use the script... Confused
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Installation and Setup All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP