View previous topic :: View next topic |
Author |
Message |
case23_69 Smarty Rookie
Joined: 15 Apr 2004 Posts: 26
|
Posted: Wed Apr 21, 2004 9:10 pm Post subject: Extended setup headers issue |
|
|
I am having a helluva time getting Smarty setup. Here is my extended setup (Smarty_CPE.php)
[php:1:b5b3a1ea36]<?php
// load Smarty library
require('Smarty.class.php');
class Smarty_CPE extends Smarty {
function Smarty_CPE()
{
// Class Constructor. These automatically get set with each new instance.
$this->Smarty();
// BAD LOCATIONS?
$this->template_dir = 'C:/PHP/Smarty/cpe/templates/';
$this->compile_dir = 'C:/PHP/Smarty/cpe/templates_c/';
$this->config_dir = 'C:/PHP/Smarty/cpe/configs/';
$this->cache_dir = 'C:/PHP/Smarty/cpe/cache/';
$this->caching = false;
//$this->assign('app_name','CPE');
}
}
?>[/php:1:b5b3a1ea36]
Can anyone tell me what security settings should be applied to these dirs on a Window box? I think I have it setup OK, but want to make sure.
Now, I have this login page with a redirect:
[php:1:b5b3a1ea36]<?php
session_start();
// ==============================================
// Requires/Includes
// ==============================================
require_once('C:/Connections/dbConn.php');
require_once('Smarty_CPE.php');
//require_once('Smarty.class.php'); -- it works with this
// =========================== MAIN ===========================
// ===============================================
// GLOBALS
// ===============================================
$ok = true;
// Instanstiate Smarty instance
$smarty = new Smarty_CPE();
//$smarty = new Smarty;
$smarty->caching = false;
$smarty->force_compile = true;
// ===============================================
// SUBMIT
// ===============================================
if( isset($_POST['login']) && ($_POST['login'] == 'yes') )
{
$userid = $_POST['user'];
$password = ($_POST['password']);
/* DATABASE STUFF GOES HERE */
$num_rows = $result->numRows();
// Username and Password are in database
if($num_rows > 0)
{
$row = $result->fetchRow();
$result->free();
// Let's register them
$_SESSION['userid'] = $row['id_people'];
// This FAILS - see error message below
header("Location: archive.php");
exit;
}
else
{
$ok = false;
}
}
// ===============================================
// PRESENTATION
// ===============================================
/* DATABASE STUFF GOES HERE */
while($row = $users_result->fetchRow())
{
if( isset($_SESSION['user']) && $_SESSION['user'] == $row['id'] )
{
$selectedUser = $row['id'];
}
$users[$row['id']] = $row['name'];
}
$users_result->free();
$smarty->assign('NoErrors', $ok);
$smarty->assign('self', $_SERVER['PHP_SELF']);
$smarty->assign('users', $users);
// load the template
$smarty->display('cpe_login.tpl');
?>[/php:1:b5b3a1ea36]
HERE IS MY ERROR MESSAGE:
Code: | Warning: Cannot modify header information - headers already sent by (output started at <path>Smarty_CPE.php:30) in <path>cpe_login.php on line 74 |
Any Ideas? Please help.
Thanks! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Apr 21, 2004 10:37 pm Post subject: |
|
|
Does the standard demo work for you? The setup doesn't look too bad. FYI--permisissions on the window box work the same in principle as on the unix box. For IIS, this means your web user (IUSER) for the site that hosts smarty must have read/write access to the templates_c and cache dirs and must have at least read access to the templates, plugins and other involved dirs. If you run your IIS under the same account that creates the files, you probably won't notice any issues (though I would think that that is not a particularly safe way to run IIS--but I run Apache, so don't ask).
The error you are getting (headers already sent) seems to indicate a very different problem than a problem directory--are you actually issuing a header() somewhere? I can't see it in the code you posted. |
|
Back to top |
|
case23_69 Smarty Rookie
Joined: 15 Apr 2004 Posts: 26
|
Posted: Thu Apr 22, 2004 8:55 pm Post subject: |
|
|
boots,
Yes, in the // SUBMIT section:
[php:1:bc7a5646b5]<?php
// This FAILS - see error message below
header("Location: archive.php");
exit;
?>[/php:1:bc7a5646b5]
The thing is, when I don't use an inherited class; when I just do:
[php:1:bc7a5646b5]<?php
require_once('Smarty.class.php');
...
$smarty = new Smarty;
?>[/php:1:bc7a5646b5]
(As an aside: Why doesn't the documentation show Smarty() instead - after all it's a constructor)
It will work fine with the header. But this won't with the header.
[php:1:bc7a5646b5]<?php
require_once('Smarty_CPE.php');
....
$smarty = new Smarty_CPE();
?>[/php:1:bc7a5646b5] |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Apr 22, 2004 9:44 pm Post subject: |
|
|
Ahh. I guess I should check my eyes
Well, the likely reason you get that is that somewhere,you are sending output to the browser before you issue that header. Sometimes this is caused by having some whitespace before your opening <?php tag. The key is to make sure that no headers are issued once content spooling is started.
As for the aside, I also believe it should be Smarty()--perhaps that will get fixed at some point. I recently posted that not including the parens messes me up (it makes it look like a property instead of a method). |
|
Back to top |
|
case23_69 Smarty Rookie
Joined: 15 Apr 2004 Posts: 26
|
Posted: Fri Apr 23, 2004 8:37 pm Post subject: |
|
|
boots,
I agree about the constructor. My error message is a little strange too:
Code: | Warning: Cannot modify header information - headers already sent by (output started at <path>Smarty_CPE.php:30) in <path>cpe_login.php on line 74 |
Notice Smarty_CPE.php:30 - does smarty run over port 30? Neither my Smarty_CPE class or my login page have a space before the initial <?php
tag. Basically, the only difference between the working version and the nonworking version is the use of Smarty.class.php versus the use of the inherited Smarty_CPE.php class. Sessions are always a pain in the ass! |
|
Back to top |
|
case23_69 Smarty Rookie
Joined: 15 Apr 2004 Posts: 26
|
Posted: Fri Apr 23, 2004 8:52 pm Post subject: |
|
|
If I get this working, where is the best location to store the smarty directories on a WIN envirionment? My scenario is one big website that will keep having little web applications like this built into into it:
Code: | C:/InetPub/wwwroot/
------------------------- /app1/
------------------------- /app2/
------------------------- /app3/ |
SO, I believe Smarty reccomends a different set of directories for each app. But, say each app only averages 15 pages, but the site is many many pages. Would something like this be a good setup:
Code: | C:/Smarty/
-------------/app1/
--------------------/tempates/
--------------------/templates_c/
--------------------/configs/
--------------------/cache/
-------------/app2/
--------------------/tempates/
--------------------/templates_c/
--------------------/configs/
--------------------/cache/
-------------/app3/
--------------------/tempates/
--------------------/templates_c/
--------------------/configs/
--------------------/cache/ |
Or would this shared method be better:
Code: | C:/Smarty/
-------------/allApps/
--------------------/tempates/
--------------------/templates_c/
--------------------/configs/
--------------------/cache/ |
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Apr 23, 2004 10:41 pm Post subject: |
|
|
Hi case23_69,
My guess is that the :30 refers to a line number -- smarty doesn't open ports and uses the standard output and output buffering control offered by PHP.
The configuration you choose is dependant on your architecture. There are some gotcha's that you should consider when deciding what works best for you. Most notably, if you are thinking of using a shared location for your temp files, you should be aware that the filenames used in the compiled/cache directory are computed based on relative positions to the template dir. Basically, this means that if two apps have unique template dirs each having a unique template foo.tpl, the compiled file for each of them would point to the same single compiled file foo.tpl.php in your compiled directory, which is not appropriate. You can circumvent this situation by ensuring that each of your applications also uses a unique compile_id, which Smarty uses when calculating its compiled and cached file names.
see:
- http://smarty.php.net/manual/en/api.display.php
- http://smarty.php.net/manual/en/variable.compile.id.php
I think the best bet is to use separate tmp directories for each app. I use something like this:
Code: | /var/apps/
/app1
/etc # config files
/lib # application files
/template
/tmp
/cached
/compiled
/www # the public website is rooted here |
If you don't like the idea of having the /tmp dirs located in you app project directories, then perhaps move them into a tree in a temporary directory like so:
Code: | /tmp
/apps
/app1
/cached
/compiled
/app2
/cached
/compiled |
I think it is a good idea to try to create a structure that could be easily moved between a windows and linux box--so again, it depends on how you need/like to organize your systems.
BTW--how does it work when you replace "/" in your paths with DIRECTORY_SEPARATOR ? |
|
Back to top |
|
case23_69 Smarty Rookie
Joined: 15 Apr 2004 Posts: 26
|
Posted: Mon Apr 26, 2004 7:03 pm Post subject: |
|
|
Is DIRECTORY_SEPARATOR a defined constant? I couldn't find it in the documenation. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 26, 2004 8:22 pm Post subject: |
|
|
case23_69 wrote: | Is DIRECTORY_SEPARATOR a defined constant? I couldn't find it in the documenation. |
That is a PHP defined constant. |
|
Back to top |
|
case23_69 Smarty Rookie
Joined: 15 Apr 2004 Posts: 26
|
Posted: Mon Apr 26, 2004 8:40 pm Post subject: |
|
|
Thanks mohrt - I guess I knew that.
Here's another off the topic question that has nothing to do with my original post:
In the documentation's extended setup example http://smarty.php.net/manual/en/installing.smarty.extended.php, why does it call the parent constructor in the child constructor?
[php:1:a1f4b7997b]<?php
$this->Smarty();
?>[/php:1:a1f4b7997b] |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 26, 2004 9:11 pm Post subject: |
|
|
IIRC that forces the parent constructor to initiate when the child is instantiated. |
|
Back to top |
|
case23_69 Smarty Rookie
Joined: 15 Apr 2004 Posts: 26
|
Posted: Mon Apr 26, 2004 9:19 pm Post subject: |
|
|
What is IIRC? And isn't this accomplished when the child is instantiated? |
|
Back to top |
|
case23_69 Smarty Rookie
Joined: 15 Apr 2004 Posts: 26
|
Posted: Mon Apr 26, 2004 9:21 pm Post subject: |
|
|
Sorry:
What I meant was: Isn't this like instantiating 2 objects instead of one? Don't we just want to instantiate the child object? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 26, 2004 9:33 pm Post subject: |
|
|
case23_69 wrote: | What is IIRC? |
If I Recall Correctly
case23_69 wrote: | And isn't this accomplished when the child is instantiated? |
I don't think the parent constructor gets executed when the child is instantiated, so this is necessary. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 26, 2004 9:34 pm Post subject: |
|
|
case23_69 wrote: | Sorry:
What I meant was: Isn't this like instantiating 2 objects instead of one? Don't we just want to instantiate the child object? |
Only the child object is instantiated, then executes the parent constructor within the child constructor. |
|
Back to top |
|
|