Zend Framework CSS issue - php

I am new to ZF but have been looking into one specific issue I am having. I am currently trying to append a stylesheet to my site through the layout.phtml file. It works fine when the URL remains at the index action of a controller however if I go to site/controller/method the stylesheet presents incorrectly. I am doing everything right I believe. I have used the following code on my site to append the stylesheet:
<?php
$this->headLink()->appendStylesheet($this->baseUrl('stylesheets/style.css'))
->appendStylesheet($this->baseUrl('stylesheets/jplayer.css'))
->appendStylesheet($this->baseUrl('stylesheets/contact.css'));
echo $this->headLink();
$this->headScript()->appendFile("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
echo $this->headScript();
?>
I have also tried doing this from the controller action minus the echo part which ends up breaking the page all together.
EDIT: I got the css to show up now but the font wont display the correct one. Has anyone experienced this and could this be a part of my css directing to the incorrect path or the font breaking somewhere.

Keep stylesheets folder in public direcory of your project
<?php
$this->headLink()->appendStylesheet('stylesheets/style.css');
$this->headLink()->appendStylesheet('stylesheets/jplayer.css');
$this->headLink()->appendStylesheet('stylesheets/contact.css');
echo $this->headLink();
$this->headScript()->appendFile("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
echo $this->headScript();
?>
Hopes it will solves your problem

Related

PHP echo include variable in <head><title>

I am building a small personal website. To keep things small and to avoid writing things over and over again, I have a single header.php file that every sub-directory index.php file include's. So, every index.php file has these lines:
$title = someTitleVariableOrMethod;
include('/var/testsite/docroot/header.php');
And in my header.php file, I have these lines (I know I could probably improve the formatting, but first I want to get the title working).
<html>
<head>
<?php
if (isset($title)) {
echo '<title>' . $title . '</title>';
} else {
echo '<title>Sampletext</title>';
}
?>
<style>
//a bunch of irrelevant css
</style>
</head>
<body>
//this is the end of the header file, the rest is dealt with in the index.php file
But for some reason, the contents of the title and all my CSS show up at the start of <body> (I see this when I press F12 in browser) and NOTHING at all shows up in <head>. I just want the title contents to be put in the title tag. How could I fix this issue?
Thanks in advance.
Make sure that you are accessing the pages from a web server (e.g., XAMPP - then access via http://localhost/site/index.php). If you try to open them directly from your file system the PHP will simply be shown as you described. Also make sure the index.php has the closing body and html tags.
Sorry for the trouble, I found the issue! I was using passthru to get to content for the variable, which I didn't realize prints to the screen. My mistake!
EDIT: The site says I can't accept this answer for two days, but this is accepted

Relative pathing

Creating a wordpress sight for work to display some info. For convience i have included the following php code
<?php include 'wp-includes/fancyboxstart.php'; ?>
that file loads all the JS, and defines the div id for my fancybox img display. Recently i have changed the permalinks on my WordPress to get rid of the awful page=1 html links. Now i know to fix all my images simply by adding a "/" to the front on my img srcs. My problem is now that i have changed the permalinks it is no longer loading the JS page from above and my Image displayer no longer works =[
I have tried directly linking to it with
`<?php include 'http://premiumshotguns.com/wp-includes/fancyboxstart.php'; ?>`
but no luck. I know it's probably a simple fix but i am not seeing it! any help would be appreciated!
You probably need to include your theme path.
<?php include bloginfo('template_directory').'/wp-includes/fancyboxstart.php'; ?>

Codeigniter URL index.php twice

Hi evrybody ‘im new to codeigniter and to MVC model as well,
I need help to get my project working couse i’ve got this issues:
1) i’m in the main page and i clik on the link of the “about” page, the css file does not seems to load.
and even if i include the css in the head section the images are still missing in the page.
2) in the configure file i’ve set the
$config[‘base_url’] = ‘’;
$config[‘index_page’] = ‘index.php’;
now if i’m in the about page and i clik again on the about link the link it’s missing becouse i set the link in the menu:
About
and so the index.php it’s loaded twice: localhost/mywebsite/index.php/index.php/about.
i could set the condition to cut the link if i’m in the page i need but i would like to know if there is a more polite solution
and hope that the solution it’s not to put my hands in to the mod_rewrite .
I’ll like codeigniter because seems to be easy to configure and so really portable.
and even if it’s simple i can’t figure out how to solve this issues
Thank you everybody for your time!
Even i a newbie to CodeIgniter. I was facing the css problem. I added the css files in separate folder located at the root directory. I solved the problem by adding $this->load->helper('url'); in the controller function of the page.
You need to set $config['base_url'] in config.php to http://www.yourdomain.com and provide full path when linking css to the page like this :
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>resources/css/file.css">
just add
> <?php echo base_url();?>
before or or URL link
> (example: <script src="<?php echo
> base_url();?>assets/js/jquery-1.7.1.min.js"></script>)
to load the link to all page and separate the header and footer in separate file which could help you a lot minimize the page content.

Parent directories and PHP

I really hope there's a simple solution to this.
<?php include("header.php"); ?>
Let's say I have a php header in my root folder simply titled header.php. In that header there is a link back to the home page, main.php, and main.php is also located on the root. No problem so far. Here's what header.php looks like. Simple stuff, right?
<link href="style.css" rel="stylesheet" type="text/css" />
<div id="headerwrap">
<div id="linkbox">
<img src="images/mainlogo.png" />
</div><!-- End linkbox -->
</div>
However, let's say I have other pages in subdirectories. Subpage.php is located in a child directory of the root, and so it has to look back to the root to get the included header.php.
<?php include("../header.php"); ?>
That wouldn't be a big deal, except that header.php links back to main.php and also style sheets, none of which are in *subpage.php's directory, thus causing an error when someone on Subpage tries to get back to Main via the link in the header.
I'm just hoping there's a simple way to make this work, and that I don't have to copy and redirect all includes into every subdirectory. Also, there are too many pages to really reasonably include them all on the root. Sorry if this answer is posted elsewhere; I've looked and just have no real idea what I'm looking for. Thanks for your help. Hope all that makes sense.
You could just hard code main.php's path within header.php:
<img src="http://website.com/images/mainlogo.png" />
As opposed to a php prob this seems to be an html prob..
Your links should be relative links with a preceding / i.e.
Text
instead of
Text
how about using absolute links. header.php should also reference main.php absolutely, then there should be no troubles:
<?php include($_SERVER['DOCUMENT_ROOT'].'/header.php"); ?>
You can use the base html tag:
<base href="http://yoursite.com/" />
This way you can use that url as the base for all your links/stylesheets/images and you don't need to worry if they're in a subdirectory.
the best thing to do is to get in the habit of using
$_SERVER['DOCUMENT_ROOT']
that way you have no confusion as to what directory you're in, etc.
so including your header for example would be as simple as :
include $_SERVER['DOCUMENT_ROOT'] . "/header.php";

Is there any way to find in which file - file is included

Am sure the question is vague.
Let me try to explain.
Assume zend frame work - PHP - jquery combination.
I include jquery files in layout.phtml.
i include some files in controller.php.
some file in view.phtml
Atlast when i run and view the page . Is there any way or any tool to find which file is included through which file (layout controller or view) ??
In addition can some one explain which is the best way include js files and where . using zend framework in layout or controller or view
The only way to find where a public, static asset (JS, CSS, image, etc) is included is to trawl through the source code (using something that can "find in files" would save time).
In regards to how and where to include such assets... for global includes (common stylesheets, scripts, etc), include these in your layouts.
For specific page includes, place these in your views.
The best way to include a static asset is using the appropriate view helper. These are generally displayed in your layout file, for example
<?php echo $this->doctype() ?>
<html>
<head>
<?php
echo $this->headMeta()->prependHttpEquiv('Content-Type', 'text/html; charset=' . $this->getEncoding());
// I use "prepend" here so it comes before any page specific stylesheets
echo $this->headLink()->prependStylesheet($this->baseUrl('/css/common.css'));
echo $this->headScript();
?>
</head>
<body>
<!-- content -->
<?php echo $this->inlineScript() ?>
</body>
</html>
You can then add to these placeholders in your view scripts, for example
<?php
// index/index.phtml
$this->inlineScript()->appendFile('https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js')
->appendFile($this->baseUrl('/js/my-jquery-script.js'));
To "include" a file means very different things in PHP (where it is analogous to copying and pasting source code from another file into the current file) and HTML/JavaScript (where you are referencing another file, which the browser must make a separate HTTP request to download). What do you consider "including"? Are image tags "including" the images? At least we can easily count those references by examining HTTP requests; from the client side, it's impossible to tell what include()s went into the source code behind the rendered output. Even naive source code searching couldn't tell you thanks to autoloading. As is, your question is not well enough defined to provide a clear answer.
Controversal answer:
You don't need that.
If you need that then it's something wrong with the way your designed your application.
Note: I've learned (trial and error) that 90% of things I don't know how to do and that seem to be impossible in ZF are a result of wrong application design.

Categories