Zend Framework 1.12 - AppendStylesheet makes link to CSS file twice - php

I am doing the examples in the book "Zend Framework - A Beginner's Guide". I am almost done but I have found a few weird issues. One of them is in my admin.phtml layout file. I have this code:
<?php echo $this->headLink()->appendStylesheet($this->baseUrl().'/css/master.css'); ?>
When I load the page I see it displays the master.css link twice:
<link href="/square2/public/css/master.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/square2/public/css/master.css" media="screen" rel="stylesheet" type="text/css" />
When I comment out the appendStyleSheet() function, as expected, nothing shows up. Any reason why this function is doing it twice when I only make the call once?
Addendum: As a test I did two appendStyleSheet functions and in the resulting page I see the CSS file three times, apparently twice for the first call and once for the second. Any clues?

Just echo headLink
<?php $this->headLink()->appendStylesheet($this->baseUrl().'/css/master.css'); ?>
<?= $this->headLink(); ?>

I fixed this by using setStylesheet() instead:
<?php $this->headLink()->setStylesheet($this->baseUrl().'/css/master.css'); ?>
As explained by Joel Joel Binks, the first call to appendStylesheet() appends the stylesheet and returns it. The second call returns any previously appended stylesheets plus the second stylesheet hence the first stylesheet will appear twice.

Related

Website styling not being applied. (Calling stylesheet.css from a php include)

I wonder whether anyone could help me resolve some problems I'm having in creating a website using HTML, CSS...and PHP for the first time. (My previous attempts at web design were only in HTML and CSS).
The problem at present is that my home-page (index.php) somehow isn't 'seeing' my stylesheet.css.
The code for the index.php is basically as follows :
<?php
$page_title='Home';
[php-code here, to call in include1.php.....Please see below for details]
?>
<div class="copy">
[page content here, in html]
</div>
<?php
[php-code here, to call in include2.php.....Please see below for details]
?>
My folder structure is :
web
css
stylesheet.css
images
logo.png
includes
include1.php
include2.php
index.php
In attempting to call in include1.php (containing doc type declaration, and Head section including reference to stylesheet.css), I've tried the following (inserted between <?php and ?>, as shown above), all without success :
$pathtoinclude1 = $_SERVER]'DOCUMENT_ROOT'];
$pathtoinclude1 .= "/includes/include1.php";
include_once($pathtoinclude1);
and
include('/includes/include1.php')
In include1.php, my reference to the stylesheet.css is :
<link rel="stylesheet" href="../css/stylesheet.css" media="Screen" type="text/css"/>
When I preview the home-page, all I get is the text in default font (Times New Roman?). None of the styling via CSS is being applied.
Can anyone give me some pointers as to what I'm doing wrong?
If that first answer doesn't work, try replacing
<link rel="stylesheet" href="../css/stylesheet.css" media="Screen" type="text/css">
with <?php include 'style.php'?>
And then in the style.php file include the <style> tags and then add the css regularly.
Since you say you are using php for the first time, make sure you have the correct html declaration.
although you have already worked with html,css just a reminder:
<?php
$page_title='Home';
[php-code here, to call in include1.php.....Please see below for details]
?>
<!DOCTYPE html>
<html>
<head>
<!-- MAKE SURE YOU'RE INCLUDING THE
EXTERNAL CSS FILE HERE BUT NOT TO INCLUDE YOUR PHP INCLUDES!
WHICH ACCORDING TO YOUR FILE STRUCTURE SHOULD BE -->
<link rel="stylesheet"
href="../css/stylesheet.css"
media="Screen"
type="text/css"/>
</head>
<body>
<div class="copy">
[page content here, in html]
</div>
<?php
[php-code here, to call in include2.php.....Please see below for details]
?>
</body>
</html>
When you include() the file from index.php, the path looks like:
<link rel="stylesheet" href="../css/stylesheet.css" media="Screen" type="text/css"/>
This path is going one directory back from index.php which is not a valid path. Your path in include1.php should look like this when you include it in index.php:
<link rel="stylesheet" href="css/stylesheet.css" media="Screen" type="text/css">
Also, if CSS includes properly but styles still do not show up, try removing browser cache.
Try this. It worked for me
Let's assume that you CSS file is named 'css.css'
And it is located in the same directory with you home page.
Just add this at the head tag:
Head
Style
<?php include('css.css') ?>
style
head
Don't forget to add corresponding tags

Php - CSS elements wont load

I am new to this board and since I sadly couldn't find the answer while searching for it, I thought I should post it here :P
Enough from me, I've got the following problem:
I made a website (for practice) and tried to make a guestbook in it.
Worked out pretty well so far, yet I have one big problem. As soon as I try to get from one .php page to another .php page and include a HTML page on there, it wont load the CSS elements anymore.
When going from a .html page to a .php page and including a HTML page, it works perfectly fine.
I've also checked if the path are correct, and if this bug appears on more than just that one .php page, and yea, it made always problems in that scenario.
Here are the include and stylesheet I am using (I hope that's all you need as information)
include('gaestebuchAfterLogin.html');
<link rel="stylesheet" href="../../css/style.css" type="text/css">
Edit:
here is some more code:
<?php
session_start();
?>
<?php
if(isset($_SESSION["login"]))
{
include('gaestebuchAfterLogin.html');
}
else
{
include('gaestebuchFail.html');
}
?>
<?php
session_start();
?>
^ one PHP Element
<?php
if(!isset($_SESSION["username"]))
{
echo "Bitte erst einloggen";
exit;
}
?>
^ the second PHP Element (for example)
well, as said, the include works perfectly fine, when i haven't been on a .php page before. But if i have been on a php page before, it wont work anymore
Edit2:
sorry for posting in answers and thanks for the quick responses :P
Anyways, tried to use the absolute path now, did not work out, too
try and use absolute paths instead, change:
<link rel="stylesheet" href="../../css/style.css" type="text/css">
into:
<link rel="stylesheet" href="/css/style.css" type="text/css">
This:
<link rel="stylesheet" href="../css/style.css" type="text/css">
Or create a path variable from root using $_SERVER to get your url.
Define it and then include your php in the page.
$app_url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
define("APP_URL",$app_url);
and then
<link rel="stylesheet" href="<?php echo APP_URL?>css/style.css" type="text/css">

CSS linking issues

i need some help with linking css to a php file.
This was completed by someone else and now i need to fix it. We have the main css that controls the look and feel of the entire site. The other CSS is just for the accordions page. that needs to be added in.
Current links include:
<!-- CSS Linking -->
<link href="css/template.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/accord.css" rel="stylesheet" type="text/css" />
If i remove the ?php echo from the second one it doesn't work, but if i leave it in there the css/template.css doesn't work.
Basically if both are in there are the same time they one doesn't work. Is there are way to resolve this?
The answer was that in the css of the second file there was an element of code that was overwriting the other file. The people had a body element. This has been removed and now both working together well.

Issue linking CSS to backend Zend Framework 1

I am working on a Zend Framework 1 application. It is successfully installed on my localhost and is working without any problems. However I've noticed that the css for the back end of the application is not working.
When I view the page source I can see the stylesheet has been loaded and can click on the link to it to view in the browser.
However the style is not applied to any of the elements on the screen and I do not understand why.
This is the layout file for the page: (adminstyle.css is not loading...)
<link href="/css/adminstyle.css" media="all" rel="stylesheet" type="text/css" title="default" />
<link rel="stylesheet" href="/css/smoothness/jquery-ui-1.10.2.custom.min.css">
<link rel="shortcut icon" href="images/favicon_2.ico" />
</head>
does anyone know what might be causing this issue? Apologies for the question if it seems stupid but I'm not really experienced with this sort of thing and I am trying to get to the bottom of it. Any help is much appreciated.
I can provide more details if required, I just do not want to post lots of unescessary snippets of code up.
Here is the right way to write links in zend framework cause with your way it will work just for the index/index , for other view you won't get the style css applied :
<link rel='stylesheet' type='text/css' href="<?php echo $this->baseUrl()."/css/style.css"; ?>" >
the same for your js files
hope it helps.

PHP Page-Specific Scripts and Styles Not Recognized

I have a site built with PHP includes. For scripts and styles that are used on only one page, I call them with a variable. So the header include contains this line:
<?php echo $additional; ?>
And a particular page that requires additional scripts and styles contains these lines:
<?php $additional = '<link href="/assets/style_tabbedpanels_calendar.css" rel="stylesheet" type="text/css" /><link href="/assets/style_calendar.css" rel="stylesheet" type="text/css" /><script src="/assets/script_tabbedpanels_t-l.js" type="text/javascript"></script><script src="/assets/script_calendar.js" type="text/javascript"></script><script src="/assets/script_yahoo-dom-event.js" type="text/javascript"></script>'; ?>
I didn't break each style and script onto a new line because I found that causes problems. Generally, this has worked fine, but the calendar and yahoo-dom-event scripts that I just added aren't running at all. I know this because everything works if I put them directly in the header include.
So I was wondering if I'm doing something wrong when defining the additional variable on the individual pages?
Thank you.
The problem seemed to be the order of the scripts. When I moved the yahoo one in front of the others, it started working.

Categories