tomb04 Posted March 1, 2010 Share Posted March 1, 2010 Hello, When I open the main index.php file in the browser, the stylesheet is not displaying at all. My header file is called ViewHelper.php and Footer file name is called index.php. Both of these files are in a subfolder called views. My stylesheet file name is main.css in the stylesheet folder. To clarify I have a main folder called test. Inside this folder I two subfolders as explained above. Where am I going wrong? Thanks in advance ViewHelper.php code... <?php class ViewHelper { static function DisplayHeader($pageTitle = "") { echo("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); echo("<html>"); echo(" <head>"); echo(" <title>{$pageTitle}</title>"); echo(" <link href="stylesheet/main.css" media="all" rel="stylesheet" type="text/css"/>"); echo(" </head>"); echo(" <body>"); } static function DisplayFooter() { echo(" </body>"); echo("</html>"); } } ?> index.php code... <?require_once("ViewHelper.php");?> <?ViewHelper::DisplayHeader("Blog index");?> <h1>Blog index</h1> <p>You can <a href="index.php?cmd=BlogAddForm">add messages</a> !</p> <form action="index.php" method="post"> Search: <input name="search"> <input type="submit" value="Search!"> </form> <?php foreach($data as $messages) echo("<div class=\"message\"> <h2>{$messages['title']}</h2> <p>{$messages['message']}</p> <a href=\"index.php?cmd=BlogDelete&id={$message['id']}\">Delete this message</a> </div>"); ?> <?ViewHelper::DisplayFooter();?> Quote Link to comment Share on other sites More sharing options...
schilly Posted March 1, 2010 Share Posted March 1, 2010 you need to escape your quotes change echo(" <link href="stylesheet/main.css" media="all" rel="stylesheet" type="text/css"/>"); to echo(" <link href=\"stylesheet/main.css\" media=\"all\" rel=\"stylesheet\" type=\"text/css\"/>"); or echo(" <link href='stylesheet/main.css' media='all' rel='stylesheet' type='text/css'/>"); Quote Link to comment Share on other sites More sharing options...
tomb04 Posted March 1, 2010 Author Share Posted March 1, 2010 I tried both of your codes and it didn't work. Quote Link to comment Share on other sites More sharing options...
schilly Posted March 1, 2010 Share Posted March 1, 2010 whats the head code its outputting? Quote Link to comment Share on other sites More sharing options...
tomb04 Posted March 2, 2010 Author Share Posted March 2, 2010 Not sure what you mean. Are you asking the main index.php (that handles all user requests) or css file. By the way I don't have html file, but I assume I don't need that. Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted March 2, 2010 Share Posted March 2, 2010 <?require_once("ViewHelper.php");?> replace this with <? include($_SERVER['DOCUMENT_ROOT'].'/views/ViewHelper.php'); ?> Quote Link to comment Share on other sites More sharing options...
jl5501 Posted March 2, 2010 Share Posted March 2, 2010 Firstly be consistent with your php open tags. You should always use the long form open tag <?php as the short open tag <? is not guaranteed to work on all servers. Secondly your stylesheet include is echo(" <link href="stylesheet/main.css" media="all" rel="stylesheet" type="text/css"/>"); That might need to be echo(" <link href="/stylesheet/main.css" media="all" rel="stylesheet" type="text/css"/>"); Also to check, if you use firefox to view the site, go into view source, and see the include of the css file. Assuming you see it, click on it, and it will show you the css file, if it has found it, else give you a 404, so then you will know for certain if your stylesheet is being found. Quote Link to comment Share on other sites More sharing options...
tomb04 Posted March 2, 2010 Author Share Posted March 2, 2010 I cannot see the include css in the view souce. So what is this telling me? I am working on a sample work, so according to the tutorial, the frames and backgound colour should be displaying. Also I should tell you that in views\index.php file the foreach loop shown in the tutorial had without the php tags. I put them there. Even without the php tags the css will still not show and also the contents will not show correctly. So that is why I had to put the tags there. So orginally the foreach code is like this... <? foreach($data as $message) echo("<div class=\"message\"> <h2>{$message['title']}</h2> <p>{$message['message']}</p> <a href=\"index.php?cmd=BlogDelete&id={$message['id']}\">Delete this message</a> </div>"); ?> Quote Link to comment Share on other sites More sharing options...
jl5501 Posted March 2, 2010 Share Posted March 2, 2010 ok so just to make sure, your index.php now starts like this ? <?php require_once("ViewHelper.php"); ViewHelper::DisplayHeader("Blog index"); ?> so lets make it tell us what is going wrong <?php ini_set('display_errors','on'); error_reporting(E_ALL); require_once("ViewHelper.php"); ViewHelper::DisplayHeader("Blog index"); ?> And see if you get any error messages there. It looks as if you are not managing to include the class file, but this will tell us. Quote Link to comment Share on other sites More sharing options...
tomb04 Posted March 2, 2010 Author Share Posted March 2, 2010 I got this error. Is this what you were expecting? Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\test\views\ViewHelper.php on line 11 line 11 is this code echo(" <link href="/stylesheet/main.css" media="all" rel="stylesheet" type="text/css"/>"); in the ViewHelper.php file Your code is placed like this... <?require_once("ViewHelper.php"); ViewHelper::DisplayHeader("Blog index");?> <?php ini_set('display_errors','on'); error_reporting(E_ALL); require_once("ViewHelper.php"); ViewHelper::DisplayHeader("Blog index"); ?> <h1>Blog index</h1> <p>You can <a href="index.php?cmd=BlogAddForm">add messages</a> !</p> <form action="index.php" method="post"> Search: <input name="search"> <input type="submit" value="Search!"> </form> <?php foreach($data as $messages) echo("<div class=\"message\"> <h2>{$messages['title']}</h2> <p>{$messages['message']}</p> <a href=\"index.php?cmd=BlogDelete&id={$message['id']}\">Delete this message</a> </div>"); //pagination probably need to go here ?> <?ViewHelper::DisplayFooter();?> Quote Link to comment Share on other sites More sharing options...
schilly Posted March 2, 2010 Share Posted March 2, 2010 this wont work: echo(" <link href="/stylesheet/main.css" media="all" rel="stylesheet" type="text/css"/>"); you need to escape your quotes or use single quotes inside double quotes. see my first post. change that line then see what error you get. Quote Link to comment Share on other sites More sharing options...
tomb04 Posted March 3, 2010 Author Share Posted March 3, 2010 I have been using a different css file to the one in the example (doh!) but it only works with the code that jl5501 gave. Also when using jl5501 code I can see the css file and clicking on it, in the view source. So not sure if I should put the status solve. Thanks for your help to both of you. <?php ini_set('display_errors','on'); error_reporting(E_ALL); require_once("ViewHelper.php"); ViewHelper::DisplayHeader("Blog index"); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.