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?
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
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:
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.
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.
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!
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
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.