index.ctp is styled but rest of the pages are not - php

index page is styled while rest of the pages are not.When i checked cascading style sheets(CSS) files in browser, I was surprised to see those CSS files are not accessible for all pages except of Index.ctp. All pages are in same folder and same links are given to access cascading style sheets then why those CSS files are not accessible for other pages.I tried enough to resolve this but could not. i tried to fin solution of this on Google but can't find any solution.

Include the stylesheets on default.ctp layout in View/layout not on index.ctp.

in your comment
controler name is FrontsController and folder iname is Fronts. css and js files are in css, js folders respectively. i using this way to add css file in about page. – user3623305 35 mins ago
add a comment
change path for css to be href="/css/reset.css"
Anyways it better to include your css files using html helper like this
echo $this->Html->css('css_name');
if your css file is at app/webroot/css, and it's name is main.css, use
echo $this->Html->css('main');
For more information look here http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::css

Related

Images which where added on html from css won't display when that particular css file is kept inside a folder

On my project work I have got two css file one for index-page another for home-page.I thought that I should keep those two css files on a folder so, if on coming days if i added more css files then it will be easy for me to find them all in one folder so, i did.I have one folder for images also.
My question is that when I add an image from css (background-image property) to my any page it won't display there but other images which were added from html img src=' ' property they are all displayed.
when i again placed that two css files from it's css folder to outside together with index.php,home.php then all those image which were not shown earlier by css background-image property were shown again! what may be the reason behind happening that???
I think you may have a filepath issue here, though I don't have much information to go on. If your css files are in let's say "main/css/" and you're trying to access an image in a directory above it, then you're either going to have to give the background-image src an absolute path or use ../ to break out of your current directory. Example:
if your image resides in the main folder 1 level above your css folder:
#myImage {
background-image: src("../myImagePic.png");
}
This is probably the reason why when you add the image from your HTML file that's in the main directory it works and then in your CSS which is located inside a CSS folder inside of the main directory it doesn't work. Hopefully this helps, didn't have much to go on.

common elements php html navbar

I am trying to make a template for my website.
Basically taking out all the common stuff out using php's include function.
I have made a navigationbar.php and samplepage.php.
navigationbar has all the links to stylesheets etc.
When they are in the same folder and I include navigationbar.php in samplepage it works just fine.
However when i move samplepage.php to a subdirectory (leaving navigationbar.php in the same folder) and
link navigationbar.php with the menu doesn't come formatted.
it seems samplepage is getting contents from navigationbar.php but navigationbar is not linking to the css files.
Can anyone tell what I'm doing wrong here?
i'm using xampp and have tried with both relative and absolute paths- (include '../navigation.php' and 'localhost/folder/navigation.php')
Make the paths of your css files absolute (i.e. start with / and specify the full path). This will allow them to work correctly from any path.
When including a file in PHP, the url's are relative to the file you are including into. Not to the file you are including.
So you need to change your paths 'navigationbar.php'
Try using something along the lines of this to link to your header/footer files:
include($_SERVER['DOCUMENT_ROOT'].'/path_to/header.php');
and then appropriately link to your .js/.css files within header.
Where your PHP files are has no direct influence. You have to make sure that the resulting HTML has the correct paths to all CSS/JS/img files etc. You may want to post your file structure here and show the code that calls the relevant CSS files.

How to automatically include/load css and js from modules in CodeIgniter using HMVC

I have some modules in modules folder that have css and js folder and I am thinking of the way how to approach the automatic load of all this css and js files to my header of the template.
I was thinking of creating 2 modules called cssloader and jsloader that will be included in the header section of the template.
They would contain some php script that will put the urls of css (and js) in an array and this array will be outputed in the template like e.g.:
<?php echo Modules::run( 'cssloader/cssloader/_css_include_for_frontend' ); ?>
The urls will be grabed by some script that will be searching modules folder of the CI application and looking for css folder within and a file load_css.php with some defined constants or variables like
$css_loader_frontend['slider'] = array('slider.css',
'slider_ie6.css'
);
$css_loader_backend['slider'] = array('slider_admin.css');
This file will contain files that will be loaded e.g. slider.css (within slider module css folder)
And the similar scenario for javascript stuff.
Is my approach right or not and you would do it somehow different?
What do you think about it?
What would you do different and more effective?
Thanks
I Think this template class can help you, though, I was wondering why are you accessing assets files inside modules, I'm not well versed but as far as I know you should access files such as img, js, css and so on just on the level of system and application folders in a folder that could be named "public" or "assets" to avoid "Directory access is forbidden."

How to dynamically control paths in static CSS files with MVC code igniter project

I'm creating a website/codeigniter-project that uses views which link to external CSS files.
Everywhere throughout my project/web-page's views I can control the URL paths of images, links, etc by constructing them from the 'base_url' setting variable. I don't have any control over static, linked external CSS files. This means that whenever my base URL path changes for my site I have to go through my CSS files and do global search/replaces to update all my paths.
To solve this I thought about creating a controller just to load CSS/JavaScript files and treating the actual files like views with hooks but I was talked out of this by #WesleyMurch in this question:
Using a controller to handle returning customized css & javascript files with codeigniter
How can I dynamically assign base-paths to my css assets so I don't have to do global search and replaces every time I update the base path of my site?
For this I use a view file containing css code with all the variables. The only change is that you should set appropriate headers for CSS
Create function style in your controller and set it to render appropriate view file (style.php). Code all your css with php code in style.php.
Set following headers at the start of the function:
header("ContentType: text/css");
header("Expires: <some far future expiration time or use mod_expires with apache>");

ATK4 - subfolder under page folder and js/css issue

I am using agile toolkit for one of my projects. When I create a sub folder under page folder, CSS and JS are not picked from atk4 folder and I have to copy those css and js under templates folder. Is this the right way of doing this?
Yes. With Agile Toolkit, the files are loaded from atk4/* by default. If you want to override any of those files including templates, css, images, classes or templates, you should copy them outside.
for example:
atk4/template/jui/css/general.css -> template/jui/css/general.css
atk4/lib/Tabs.php -> lib/Tabs.php
If you are including CSS files or linking to images, it's a good practices to use
<?template?>img/myimage.png<?/?>
in your own templates. That instruct Agile Toolkit to locate the resource and links to it properly.
As romans said, you can put your own files in the /templates/default/css folder (It's called jui in 4.0 but default in 4.1) and these should be picked up by the pathfinder.
You can also add additional directories to the list searched by adding them in Frontend.php like this.
$this->addLocation('atk4-addons',array(
'php'=>array(
'mvc',
'misc/lib',
'sterling/jqplot/lib',
),
'css'=>array(
'sterling/jqplot/templates/js/jqplot',
),
so now the pathfinder will also search for css scripts in the directory specified and i can add the following line into my page code.
$p->api->template->append('css_include', '<link type="text/css" href="'.$this->api->locateURL('css','mysite.css').'" rel="stylesheet" />'."\n");
Relative path,
Look:
Some Directory
templates/index.html { `<script src='test.js'></script>` }
index.php
If you want include index.html with test.js you must change relative path - from test.js to templates/test.js
edit: look : Click

Categories