• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic CSS/JS Files Not Working

#1
[eluser]Bluemill Media[/eluser]
Hi Everybody,

I'm working on a dropship ecommerce platform, and have a section of the site where I need to enable members to create templates for their stores.

I'm using Smarty to parse template data. Also, because of the way my software is setup, I'm using controllers and views to dynamically generate CSS, JS, Images, etc. However, firebug reports all of my external files as 404s, and none of my styles or scripts are applied/executed, but I can access my CSS and JS files directly with no problem.

Here is my htaccess:

Code:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9\.-]+)/?$ index.php?c=home&slug;=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9\.-]+)/([a-zA-Z0-9\.-]+)/?$ index.php?c=home&slug;=$1&m;=$2 [QSA,L]
RewriteRule ^([a-zA-Z0-9\.-]+)/([a-zA-Z0-9\.-]+)/([a-zA-Z0-9\.-]+)/?$ index.php?c=home&slug;=$1&m;=$2&i;=$3 [QSA,L]

My Controller:

Code:
<?php

class Home extends Controller {

    function __construct() {
        // GRAB NECCESSARY DATA
        parent::Controller();    
        global $wpdb, $UserTools, $StoreTools;
        $this->wpdb = $wpdb;
        $this->UserTools = $UserTools;
        $this->StoreTools = $StoreTools;
    }
    
    function index() {
        // PERFORM PAGE ACTIONS
        $this->load->library('encrypt');
        $StoreSlug = (isset($_GET['slug'])) ? $_GET['slug'] : NULL;
        $StoreInfo = $this->StoreTools->store_info_slug($StoreSlug);
        if($StoreInfo) {
            $OwnerInfo = $this->UserTools->user_info($StoreInfo->Owner);
            $Theme = $this->StoreTools->get_theme($StoreInfo->Theme);
            $TemplateData = array(
                'StoreInfo' => get_object_vars($StoreInfo),
                'OwnerInfo' => get_object_vars($OwnerInfo),
                'Theme' => get_object_vars($Theme)
            );
            $this->load->_ci_varmap['smarty_parser'] = 'smarty';
            $this->load->library('smarty_parser');
            $this->smarty->parse('ci:'.$Theme->Name.'/home.tpl', $TemplateData);
        } else {
            die('Error loading template data.');
        }
    }
    function styles() {
        // PERFORM PAGE ACTIONS
        $this->load->library('encrypt');
        $StoreSlug = (isset($_GET['slug'])) ? $_GET['slug'] : NULL;
        $StoreInfo = $this->StoreTools->store_info_slug($StoreSlug);
        if($StoreInfo && isset($_GET['i'])) {
            $Theme = $this->StoreTools->get_theme($StoreInfo->Theme);
            header("Content-type: text/css");
            $this->load->view($Theme->Name.'/styles/'.$_GET['i']);
        } else {
            die('Error loading template data.');
        }
    }
    function js() {
        // PERFORM PAGE ACTIONS
        $this->load->library('encrypt');
        $StoreSlug = (isset($_GET['slug'])) ? $_GET['slug'] : NULL;
        $StoreInfo = $this->StoreTools->store_info_slug($StoreSlug);
        if($StoreInfo && isset($_GET['i'])) {
            $Theme = $this->StoreTools->get_theme($StoreInfo->Theme);
            header("Content-type: text/javascript");
            $this->load->view($Theme->Name.'/js/'.$_GET['i']);
        } else {
            die('Error loading template data.');
        }
    }

}

?>

home.tpl (Main view file)

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
    &lt;title&gt;{$StoreInfo.Name}&lt;/title&gt;
    &lt;link href="/shop/{$StoreInfo.Slug}/styles/main.css" rel="stylesheet" type="text/css" /&gt;
    [removed][removed]
&lt;/head&gt;
&lt;body&gt;
<p><strong>Description:</strong> {$StoreInfo.Description}</p>
<p><strong>Owner:</strong> {$OwnerInfo.FirstName} {$OwnerInfo.LastName}</p>
<p><strong>Theme:</strong> {$Theme.Name}</p>
&lt;/body&gt;
&lt;/html&gt;

main.css

Code:
body {
    background-color: #000;
    color: #888;
}

Firebug Header Info:

Code:
Response Headers

Date                Sat, 26 Jul 2008 18:49:51 GMT
Server              Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5
X-Powered-By        PHP/5.2.5
Expires             Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control       no-cache, must-revalidate, max-age=0
Pragma              no-cache
X-Pingback          http://dev.petecommerce.com/xmlrpc.php
Last-Modified       Sat, 26 Jul 2008 18:49:51 GMT
Content-Encoding    gzip
Vary                Accept-Encoding
Content-Length      69
Keep-Alive          timeout=5, max=98
Connection          Keep-Alive
Content-Type        text/css

Request Headers

Host                dev.petecommerce.com
User-Agent          Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Accept              text/css,*/*;q=0.1
Accept-Language     en-us,en;q=0.5
Accept-Encoding     gzip,deflate
Accept-Charset      ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive          300
Connection          keep-alive
Cookie              (!HIDDEN!)
If-Modified-Since   Sat, 26 Jul 2008 07:13:48 GMT
Cache-Control       max-age=0

Response

body {
    background-color: #000;
    color: #888;
}

Any help is greatly appreciated. Smile

(Please let me know if you need more information, and what exactly you need.)

#2
[eluser]Bluemill Media[/eluser]
Hey all,

I still haven't had any luck figuring this out. It's getting pretty 'hot' over here, so I figured I'd bump the thread.

Anybody got anything?

#3
[eluser]Randy Casburn[/eluser]
Hi Blue -- Here something to start with...

In your constructor function the first thing I noticed was the global keywork...(yuck) but I'll get over that ;-)

Code:
global $wpdb, $UserTools, $StoreTools;


Then later it dawned on me that in the index method you're attempting to use $StoreTools in on Object construct...

Code:
$StoreInfo = $this->StoreTools->store_info_slug($StoreSlug);


If this is truly a PHP object, you'll need to either grab and instance of it or clone it before you can call it's methods.

Check out the HTML source of the page and you may see the PHP error there. Also, turn on logging in CI while you're developing and dump the logs. That's helpful too.

I hope this get's you started or at least is a little helpful.

Randy

#4
[eluser]Bluemill Media[/eluser]
Thanks Randy Smile

I'm actually grabbing the instance of the $StoreTools object elsewhere in the project (From outside of CodeIgniter...I know, ugh...but there is a method to my madness Tongue). I can access and use the methods from the object just fine...the problem is that my external files aren't being applied. So, this leads me to believe that the problem is either somewhere in my .htaccess or in relation to caching.

The former seems to be supported by the fact that I'm able to get the files to work great if I reference them directly (i.e. /system/app-shop/views/Red/styles/main.css)...with the Dynamic option (/shop/lorren/styles/main.css) firebug gives me a 404 error in the net panel. The problem there is I need the app to appear to provide host-level domain functionality.

#5
[eluser]Randy Casburn[/eluser]
I just helped someone else through a similar problem with dynamic images. As it turned out, each time that person undid their tweaks to CI (read custom code) everything worked perfectly.

Do you have any customizations in the Core?

Are there any other "things" that are working inconsistently? Not sanely? That seem remotely related? Do all the controllers work normally given you .htaccess configuration, etc.

Grasping at straws.

The only thing the CI Loader class does when it loads up the View file to serve it up is ensure that it exists. If it doesn't, it invokes the exception handler and posts a nasty message saying the file could not be found.

Have you checked your CI log files?

Randy

#6
[eluser]Bluemill Media[/eluser]
I actually haven't thought to check the log files yet... Go figure, lol...that's clumsy me.

Anyhow, I'm heading out for the night but will post back more tomorrow after I've done that. (Don't want to leave you hanging.)

Thanks again! Smile

P.S. Yes, everything else is working great. And no, I don't have any mods to the core...just simple mods to some error files to display more user friendly messages and the smarty library add-on.

#7
[eluser]Randy Casburn[/eluser]
[quote author="Bluemill Media" date="1217318768"]Thanks Randy Smile

The former seems to be supported by the fact that I'm able to get the files to work great if I reference them directly (i.e. /system/app-shop/views/Red/styles/main.css)...with the Dynamic option (/shop/lorren/styles/main.css) firebug gives me a 404 error in the net panel. The problem there is I need the app to appear to provide host-level domain functionality.[/quote]

duh...this just dawned on me. Something was bugging me about this paragraph and I couldn't pinpoint what it was. You're examples that work and don't work are both relying on the URI class while your application is relying on URL parameters and $_GET retrievals.

Perhaps you should investigate that inconsistency. Maybe that will help you track it down more quickly with the help of the log files.

Randy

#8
[eluser]Bluemill Media[/eluser]
Hey Randy,

Sorry, been busy for a few days. Anyhow, neither example (working or non-working) is relying on the URI class. In fact, I've set CI to use QueryStrings and am using mod_rewrite for the pretty URLs. (I think this is more efficient)

- /system/app-shop/views/Red/styles/main.css - is an absolute path to the physical file
- /shop/lorren/styles/main.css - is using basic mod_rewrite (included in my first post)

Anyhow, thanks for your help! I'm still working on this, and I'll post back here as I figure things out.

#9
[eluser]Randy Casburn[/eluser]
[quote author="Bluemill Media" date="1217480320"]
- /system/app-shop/views/Red/styles/main.css - is an absolute path to the physical file
- /shop/lorren/styles/main.css - is using basic mod_rewrite (included in my first post)
[/quote]

Yea I knew you were using Query strings, that was quite evident. I misunderstood what you meant by "access them directly" then. Thanks for clarifying.That really had me perplexed. So by "access them them directly" means this works:

&lt;link href="/shop/{$StoreInfo.Slug}/styles/main.css" rel="stylesheet" type="text/css" /&gt;

and this doesn't:

$this->load->view($Theme->Name.'/styles/'.$_GET['i']);

give a url such as http://dev.petecommerce.com/index.php?c=...i=main.css

Right?

Randy

#10
[eluser]Bluemill Media[/eluser]
This does not work: &lt;link href="/shop/{$StoreInfo.Slug}/styles/main.css" rel="stylesheet" type="text/css" /&gt;

This does work: &lt;link href="/system/app-shop/Red/styles/main.css" rel="stylesheet" type="text/css" /&gt;

(Please note that {$StoreInfo.Slug} outputs as the name of the user, e.g. 'lorren'.

Regarding the query based URL, I've tried that during debugging and it didn't give me a solution. Also, keep in mind that these URLs are going to be used by store owners/template designers, so the URLs need to be pretty and user-friendly.

Also, it's important to note that in using the developer toolbar I can 'CSS > View CSS' and it takes me directly to the stylesheet with all styles displayed, but they're just not being applied. Simplified: I'm pointing to the correct file with every URL type...the browser just isn't reading the styles in the file through...to make matters even more odd, Firebug reports the pages as 404s in the NET panel...

I'm at a total loss.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.