Part of the EllisLab Network
   
 
Path to CSS doesn’t work a second time
Posted: 30 October 2007 12:11 PM   [ Ignore ]  
Summer Student
Total Posts:  13
Joined  10-29-2007

I have read the topics on CSS and JS but I still don’t understand why this is happening. If i call a view with a link to ‘default.css’ it works and if i press a menu item (for example /welcome/news) then using the same path to ‘default.css’ it doesn’t seem to work anymore, why is this?

Here is the ‘default.css’ link:

<link rel="stylesheet" href="system/application/views/default/css/default.css" type="text/css" />

first item:

index.php

second item:

index.php/welcome/news

both use the same ‘default.css’ link/path

Profile
 
 
Posted: 30 October 2007 12:20 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  298
Joined  09-11-2007

Scouser,

It’s not a good pratice do this.

Why you create a folder to keep all these kind? (css, images, javascript)

I use a /public folder. In the same level than system.

So i call like that

<img src="/public/images/find.png" />

Or, use

<img src="<?=base_url();?>public/images/find.png" />

Get it?

 Signature 

cool mad
Rafael
Last.fm
Twitter

“Because they’re stupid, that’s why. That’s why everybody does everything!”

Profile
 
 
Posted: 30 October 2007 02:16 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  13
Joined  10-29-2007

The reason why I do this is because I want to be able to use multiple layouts. So I want to separate all the stuff like img/js/css and even the html views apart. In my DB ik keep a link to the active layout. If i want to create or use another layout, like for example during the christmas time or something I can switch over by just renaming my field in the DB

Profile
 
 
Posted: 30 October 2007 02:27 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  298
Joined  09-11-2007

like you wrote in your first post, what do you want will be impossible.

you can have dynamic content (images, css, even view), but you still need to show this to user. Browser don’t executes php smile

 Signature 

cool mad
Rafael
Last.fm
Twitter

“Because they’re stupid, that’s why. That’s why everybody does everything!”

Profile
 
 
Posted: 30 October 2007 07:56 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  618
Joined  12-26-2006

Hi Scouser,

<link rel="stylesheet" href="system/application/views/default/css/default.css" type="text/css" />

 

The specified path in your link is relative to the residing folder. When you change folders to index.php/welcome/news I believe it is looking for and fails to find:

/welcome/news/system/application/views/default/css/default.css

Try this debug code immediately before your header <link statement /> to see where you are:

<?php echo 'cwd --> ' .getcwd(); die; ?>

 
Numerous people have opted to hard-code their css, js and img files in the root directory using this code:

<link rel="stylesheet" href="/css/default.css" type="text/css" />

Search the forum for CSS and you will find other options.

Cheers,

John_Betong
 

 Signature 

Joke of the day     (ongoing development site)

My Hippy Trail    Source code   

Latest Project

Profile
 
 
Posted: 02 November 2007 07:39 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  36
Joined  10-30-2007

Hey John,

<link rel=“stylesheet” href=”/css/default.css” type=“text/css” />

/css doesn’t work for me either.

The only way I’ve found that works is to prepend <?php echo base_url();?> to the path, which seems like a hack.

cheers,
Sherban

Profile
 
 
Posted: 03 November 2007 04:59 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  618
Joined  12-26-2006

Hi Sherbo,

In my index.php I have the following function defined which I find is handy in tracing the elusive paths. Personalise it and let us know the results.

index.php

//=================================================
  
function debug($dir='not specified', $die=false) {
      
echo '<br />index.php-> function debug(...)<br />';
      echo
'<br />'   .'LOCALHOST             ==> ' .'TRUE';
      ECHO
'<br />getcwd() --> ' .$dir;
      
      echo
'<br />'   .'$_SERVER[SERVER_NAME] ==> ' .$_SERVER['SERVER_NAME'];
      echo
'<br />'   .'$_SERVER[HTTP_HOST]   ==> ' .$_SERVER['HTTP_HOST'];
      echo
'<br />'   .'APPPATH               ==> ' .APPPATH ;           // application/
      
echo '<br />'   .'BASEPATH              ==> ' .BASEPATH ;          // C:/awww/ncgecom/system/
      
echo '<br />'   .'EXT                   ==> ' .EXT      ;          // php
      
echo '<br />'   .'SESSION[_MENU_]           ==> ' .$_SESSION['_MENU_'];    // _menu.php

      
if (isset($application_folder))
        echo
'<br />'   .'application_folder ==> ' .$application_folder;

      if (isset(
$system_folder))
        echo
'<br />'   .'system_folder ==> ' .$system_folder;

      if (
function_exists('site_url'))
        echo
'<br />'   .'site_url()    ==> ' .site_url('');

      if (
function_exists('base_url'))
        echo
'<br />'   .'base_url()    ==> ' .base_url('');

      if (
function_exists('system_url'))
        echo
'<br />'   .'system_url()  ==> ' .system_url('');

      if (
function_exists('debug'))
        echo
'<br />Yes we have debug()';

      if (isset(
$db['default']['hostname'])) {
    
echo '$db[default][hostname] ==> ' .$db['default']['hostname'];
            
}
      
if ($die){
        
die;
      
}

  }
//endfunc
  // echo debug(getcwd(), 0); die;
}

 
Try calling the function immediately before calling the

<link rel=“stylesheet” href=”/css/default.css” type=“text/css” />
 
Cheers,

John_Betong
 

 Signature 

Joke of the day     (ongoing development site)

My Hippy Trail    Source code   

Latest Project

Profile
 
 
Posted: 03 November 2007 09:48 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  716
Joined  06-07-2007

John_Beton, you might want to use a switch statement, it’s much more efficient that a series of if statements, less repetitive too, easier to read.
Also, instead of all those echo statements you can use one, with double quotes, and use curly brackets for your variables ( echo “\”{$this-img_src}=\”>”; )
just to make it a little faster/cleaner.

 Signature 

CodeExtinguisher
Download: codex2_rc14.2.zip - 219 KiloBytes of Gloriousness!
Demo: Public preview - login with preview:preview
Temporary Docs: PBWiki

Profile
 
 
Posted: 03 November 2007 08:40 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  618
Joined  12-26-2006

Hi Zaatar,

Check the code and you will notice that every if statement is a unique test. By using the switch statement I would only be able to select one item from a group.

The individual if statements was necessary to prevent PHP undeclared variable warnings and errors.

I would be grateful for a better suggestion on how to simplify the code.

Cheers,

John_Betong
 

 Signature 

Joke of the day     (ongoing development site)

My Hippy Trail    Source code   

Latest Project

Profile
 
 
Posted: 03 November 2007 08:46 PM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  716
Joined  06-07-2007

Oh, I’m sorry John, I didn’t notice, apologies.

 Signature 

CodeExtinguisher
Download: codex2_rc14.2.zip - 219 KiloBytes of Gloriousness!
Demo: Public preview - login with preview:preview
Temporary Docs: PBWiki

Profile
 
 
Posted: 04 November 2007 05:50 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2403
Joined  06-11-2007

These are all good points but it can be done almost EXACTLY how you have it now, just use:

<link rel="stylesheet" href="/system/application/views/default/css/default.css" type="text/css" />

Notice the / at the front. As with others I don’t agree with this method, but it is possible for you to sue it that way.

You could take a look at my asset helper (link in my sig). That helps you store things in modules and use full CI paths that are generated dynamically. Id greatly recommend using that helper over any other method as hardcoded ones are a pain in the ass to update!

 Signature 

Blog | Twitter | GitHub
————————-
New PyroCMS v0.9.8 Screenshots
————————
PyroCMS - open source modular CMS built with CodeIgniter
CleverAndy - get money for un-used concept designs
————————
Libraries: Asset, Cache, cURL, CLI, REST, Template

Profile
 
 
Posted: 04 November 2007 09:16 PM   [ Ignore ]   [ # 11 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  618
Joined  12-26-2006
Zaatar - 03 November 2007 08:46 PM

Oh, I’m sorry John, I didn’t notice, apologies.

Hi Zaatar,

Off topic!

Referring to your second point about inserting variables inside double quoted strings, this is the reason and also it is easier for me to debug my frequent typos smile


Single Quotes versus Double Quotes

// http://www.evolt.org/these-things-i-know-php-tips

Any time you put something in “double” quotes, you are asking PHP to check that content for a variable. So even though the following lines do not contain variables within the double quotes, PHP will still waste precious computing time scanning them anyway.
$mytext = “Dental Plan”;
if ($mytext == “Dental Plan”) {
echo “Lisa needs braces”; }

Those same three lines of code could be executed much faster if ‘single’ quotes were used in place of “double” quotes.
$mytext = ‘Dental Plan’;
if ($mytext == ‘Dental Plan’) {
echo ‘Lisa needs braces’; }

Now that may not seem like much, but having PHP check for variables where it doesn’t need to over the course of a larger script, can certainly impede run-time. Just to clarify my point, PHP will not read a variable if it is within ‘single’ quotes.

 

Cheers,

John_Betong
 

 Signature 

Joke of the day     (ongoing development site)

My Hippy Trail    Source code   

Latest Project

Profile
 
 
Posted: 05 November 2007 05:30 AM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2403
Joined  06-11-2007

I knew it! I always thought singles were probably faster but never knew why. Once again my psychic powers do me proud. :D

 Signature 

Blog | Twitter | GitHub
————————-
New PyroCMS v0.9.8 Screenshots
————————
PyroCMS - open source modular CMS built with CodeIgniter
CleverAndy - get money for un-used concept designs
————————
Libraries: Asset, Cache, cURL, CLI, REST, Template

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 114967 Total Logged-in Users: 51
Total Topics: 122423 Total Anonymous Users: 2
Total Replies: 647238 Total Guests: 481
Total Posts: 769661    
Members ( View Memberlist )