Jump to content

my stylesheet not displaying correct for my oop php


tomb04

Recommended Posts

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();?> 

 

 

Link to comment
Share on other sites

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'/>");

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>");

?>

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();?> 

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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");

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.