Jump to content

is there a forum for the advanced php video course?


derrida

Recommended Posts

hi

i cannot find a forum for the advanced php videos of Jon Lebensold.

 

in any case i am stuck with something that should be trivial but still i`m stuck.

 

in the mvc, in the view pages i want to call an external css file (easy right:), well it seem like i cannot figure the right path.

i thought that since all pages are coming through the index i just need to say: src="/css/main.css" but it does not work.

 

what am i missing?

 

best regards

Link to comment
Share on other sites

We don't necessarily have forums specifically for each of the courses, so feel free to post your PHP related questions in the PHP forum.

 

In regards to your question... How are you trying to include the CSS file? Usually it's done like this:

 

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

 

Based on your comments above, it seems like you are (incorrectly) using "src" instead of "href" which may mean that the CSS file will never load.

Link to comment
Share on other sites

  • 2 weeks later...

I'm also having this issue and it isn't a href thing.

 

I'm loading css, and js files externally and they are not referencing correctly. Usually by adding a "/" it fixes the problem, but it didn't. I also tried href="../../path/to/css.css" and href="../path/to/css.css", but it never finds the correct path.

 

The only way I got it to work was by actually doing: http://localhost/application/views/css/global.css

 

Now obviously I don't want to have to keep referencing files like that. Do you know how to fix this problem?

 

My structure is as follow:

 

index.php

.htaccess

--------------------application

----------------------------------------models

----------------------------------------controllers

----------------------------------------views

------------------------------------------------------------css

------------------------------------------------------------js

------------------------------------------------------------header.php

------------------------------------------------------------footer.php

------------------------------------------------------------(directories for each page like home/about/... etc etc..)

 

In my root index.php file, I have a front controller that initiates a new object for me from my abstract controller. Which then calls a method called render(). Render has the following:

 

public function render() {

$directory = $this->getController();

$file = !empty($directory) ? $directory : 'index.php';

 

require_once $_SERVER['DOCUMENT_ROOT'].'application/views/header.php';

//require_once $_SERVER['DOCUMENT_ROOT'].'/'.$file;

//require_once $_SERVER['DOCUMENT_ROOT'].'/application/views/footer.php';

}

 

Hope someone can see the problem. thanks.

Link to comment
Share on other sites

So, if I understand things correctly, the user views the site entirely through the index.php file? As in, no matter what URL the user enters, the user will be directed to the index page (with a bit of .htaccess magic) and then the your controller will then choose which page to show them based on the URL? And I'm assuming that you are including your css file within the header.php file...

 

If so, that means wherever your index.php file is -- that's your root folder where your relative link will start from, and you'd want to use a relative path from that location. You should be able to access your css file with either of these paths:

 

application/views/css/cssfile.css

/application/views/css/cssfile.css

 

As a quick example, consider this:

 

-- index.php (includes /includes/include.php)

-- style.css

-- /includes/

------ include.php (links the stylesheet)

 

Let's say that the index.php file includes "include.php" like this: <?php include("includes/include.php"); ?>. Within the include.php file, I link the stylesheet: <link href="style.css" media="screen" rel="stylesheet" type="text/css" />. If I use a relative path to link the CSS, the "root" folder is the index.php file (not the include.php file) so "style.css" is the correct link, not "../style.css".

 

Hopefully that explains things... Try it out and let me know if that helps fix things for you.

Link to comment
Share on other sites

argh, I was afraid of this answer. I was hoping that people could not know my structure.

If you hide the index.php file with a .htaccess file, visitors who can't see your code shouldn't be able to tell. Even if you don't, that fact alone shouldn't be an issue. As far as I know, this is a pretty standard structure -- if you use MVC and want the system to choose what to display based on the URL, I'm not sure how else you would do it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...