Jump to content
Larry Ullman's Book Forums

Importing The Css File Through Link Href


Recommended Posts

Hello

 

 

I m reproducing the website from Chapter 2 Developing web app PHP5 advanced. I am doing it though using a framework (CodeIgniter) and well it is just about linking the header.html with the css style file. For some weird reason, it does not import it, the command <link href="style.css" rel="stylesheet" type="text/css" /> does not work.

 

 

In the book the header file is in the same folder as the style.css, both of them in the includes folder, yet it is written as

 

<hlink href="./includes/style.css" rel="stylesheet" type="text/css" />, (I have tried many other paths, too, also exactly the one from the book) but it will not pick it up. Only if I actually copy and paste the full css in the body of the header file, does the css work.

 

The way I have it is: The index.php is in the View and within the View there is a folder called Includes, within which I have the header, the footer and the style.css.

 

So, Index, is logically not inside the folder Includes, but inside the Section View (from the MVC framework). Index fetches header, and footer and modules alright because the paths are fine.

 

 

 

Of course, what I am doing with CodeIgniter is not different from the book. It is the index.php the one what assembles the header, the modules and the footer. The fact that I load the View from the Controller does not have to make any difference as long as I call the index, then this file should gather the rest of the files, just as in the book. It does gather the header and the footer and the modules alright, but completely unformatted because the ridiculous issue of the css is not joining the group, unless I paste the full css code hardcoded it in the body of the header file. Would the MVC framework have an effect on why the header.html does not pick the css?

 

I realize it is a first grade question, but I am puzzled why this simplicity is giving me trouble.

 

Firebug reports a 200 OK to the query for the CSS, so it does actually find it. In fact, I changed the path to check and when it was wrong, firebug did report error. So it does fetch it.

 

http://localhost/mvc/index.php/welcome/index/includes/style.css

 

 

thank you

 

 

Alvaro

Link to comment
Share on other sites

Yes, the fact that you're using a framework makes a huge difference. I wouldn't even know where to begin helping you, as I have no experience with CodeIgniter and therefore don't know how it may be affecting things. At the end of the day, the paths still need to be correct, which is the main issue. But the path you've shown there (the bottom link) isn't even remotely correct. The path should just be ./includes/style.css or an absolute URL to style.css.

 

Also, the reason the stylesheet is referenced in the includes directory (in the book), even though the reference is in the header file, which is also in the includes directory, is that the header file is never directly executed. The header file is included by files in the primary directory, so references to the style sheet have to be relative to the primary directory.

Link to comment
Share on other sites

Hello Larry

 

 

thank you for the reply. The latest path I included at the very bottom is not what is on my script. It was just the pasted result from the Firebug console indicating that it did not show an error. The correct paths that I was using are already in the files.

 

As per the framework, alright, if that is the reason, I will have to continue by keeping the css code hardcoded in the header file instead of calling it.

 

Even though I did start to suspect what you have clarified now, that indeed the ./includes/style.css is has that path because that is actually the path from the Index.php to the css and not the path from the header even though that code is hardcoded in the header file. This makes me think that it should be possible to reproduce that from CodeIgniter.

 

CodeIgniter is about the best most simple framework I have seen and worked with, so it would be cool to integrate your model in a framework as an example, maybe some day. I tried smarty and symfony and zend and gave up, but codeigniter is so simple that in one day one gets started.

 

Thank you for your great and very accesible explanations in your books (of which I already have 3)

 

best regards

 

Alvaro

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

Yes, the fact that you're using a framework makes a huge difference. I wouldn't even know where to begin helping you, as I have no experience with CodeIgniter and therefore don't know how it may be affecting things. At the end of the day, the paths still need to be correct, which is the main issue. But the path you've shown there (the bottom link) isn't even remotely correct. The path should just be ./includes/style.css or an absolute URL to style.css.

 

Also, the reason the stylesheet is referenced in the includes directory (in the book), even though the reference is in the header file, which is also in the includes directory, is that the header file is never directly executed. The header file is included by files in the primary directory, so references to the style sheet have to be relative to the primary directory.

Link to comment
Share on other sites

I've worked with CodeIgniter once to fix the problems in another developers work - my only suggestion would be to use the absolute URL by calling:

 

base_url();

 

and then concatenating the rest of the string on - I know Firebug is returning 200 in the NET tab but frameworks can be funny things sometimes. If that doesn't work then I'm not too sure.

  • Upvote 1
Link to comment
Share on other sites

Thank you, I will give it a try and I will post whatever I get or not get.

 

UPDATE

 

hmm, you mean giving the full path from the base_url like this ?

 

<link href="http://localhost/mvc/index.php/welcome/index/includes/style.css" rel="stylesheet" type="text/css" />

 

if yes, so far that did not solve it, hmm, I am sure it shouldnt be impossible, yet ...

 

 

regards

 

 

Alvaro

 

_______________________________________________________________________________________________________________________________

 

 

I've worked with CodeIgniter once to fix the problems in another developers work - my only suggestion would be to use the absolute URL by calling:

 

base_url();

 

and then concatenating the rest of the string on - I know Firebug is returning 200 in the NET tab but frameworks can be funny things sometimes. If that doesn't work then I'm not too sure.

Link to comment
Share on other sites

Alvaro, thanks for the nice words. By the way, it really sounds to me like you're duplicating a process. I haven't worked with CodeIgniter, but most frameworks use one key file (called the bootstrap) through which all requests go. Values are passed in the URL to tell the bootstrap which specific module to include. This is what I do in Chapter 2. So to me, it sounds like you're trying to emulate a framework-like system using a framework, when maybe you should just be using the framework and ignoring the approach in that chapter (which is kind of a watered-down framework)?

Link to comment
Share on other sites

Yes, very insightful, I think it is true, because there was a resemblance between your modularized web and the concept of framework.(I know you know all this but this is more for some of the audience who may not yet be familiar with the MVC concept). With the frameworks it is 3 sections, one called MODEL where you put all the code to interact with the DB, then you have the VIEW, which is basically an HTML page and is what the user sees, and then you have the CONTROLLER, which actually monitors the traffic, and this CONTROLLER is acting as the index.php that you have. In this controller you will see a command like $this->load->view('name_of_your_html_page');

 

So, now I find myself in the situation of which way to take, the MVC or the modularized web you introduced. The thing is that the framework, as you indicated in your book, do have a lot of built in classes and it is pretty evolved in terms of security, configurations etc, for example, it has an automatated detection of whether you are local or live and accordingly changes the error reporting status. The configuration page config.php that the framework has is tremendously rich in all settings you can customize so it does a great job. Basically what I am doing is understanding all the concepts which I find in your books and then try to implement them in my settings.

 

In the past I coded my web http://www.matchandtravel.net fully procedural, as it was my first web and did not know about modularization of a Site etc and ended up with pages with over 1500 lines of code where all is mixed. They do work but I have to roll the mouse wheel for a while before I get to the line I want to modify.

 

 

best regards

 

 

Alvaro

 

==================================================================================================================================================================

 

 

 

 

Alvaro, thanks for the nice words. By the way, it really sounds to me like you're duplicating a process. I haven't worked with CodeIgniter, but most frameworks use one key file (called the bootstrap) through which all requests go. Values are passed in the URL to tell the bootstrap which specific module to include. This is what I do in Chapter 2. So to me, it sounds like you're trying to emulate a framework-like system using a framework, when maybe you should just be using the framework and ignoring the approach in that chapter (which is kind of a watered-down framework)?

Link to comment
Share on other sites

 Share

×
×
  • Create New...