Welcome Guest, Not a member yet? Register   Sign In
problem with putting css style
#1

[eluser]Niebieszki[/eluser]
I want to change the destination of application folder so i put it out of the system folder. How would look like the paths when my css style is in
Quote:project_name/application/css/styl.css
I've tried this two and nothing:
Quote:http://localhost/project_name/application/css/styl.css
Quote:C:/xampp/htdocs/project_name/application/css/styl.css
before i change the destination of aplication folder the good paths was:
Quote:http://localhost/project_name/system/app...s/styl.css

how should i change it?
#2

[eluser]Niebieszki[/eluser]
any ideas?

Maybe I do sth wrong with moving application folder what schould I do?
#3

[eluser]bretticus[/eluser]
You are confusing server-side paths with client-side paths. That might not be the best way of explaining the problem. Let's put it this way, the browser should never encounter any path to images, javascripts, or css files via application nor system. They are meant to be accessed by your server-side PHP files only. In fact, most CodeIgnitors create an asset folder in the same directory as the index.php file (the index.php file in the same folder as the system folder.) In my last project I went as far as to create a "public" folder with one PHP file that was accessible (again, index.php) so that system/applications files would be impossible to navigate to (this requires modifications to the main index.php files as to setting the application and system paths explicitly.) Here is my directory structure:

Quote:-- application
| |-- cache
| |-- config
| |-- controllers
| |-- errors
| |-- helpers
| |-- hooks
| |-- language
| |-- libraries
| |-- models
| `-- views
|-- public
| |-- css
| |-- images
| `-- scripts
|-- system
| |-- cache
| |-- codeigniter
| |-- database
| |-- fonts
| |-- helpers
| |-- language
| |-- libraries
| |-- logs
| |-- plugins
| `-- scaffolding

The public folder is the DirectoryRoot of the VirtualHost setup for Apache.
#4

[eluser]Rolly1971[/eluser]
try this in your php code:

Code:
$url = base_url() . APPPATH . '/' . 'css/styl.css';

then pass that into your view, and in your css link tag for the soure just use: <?=$url; ?>

don't forget to load the url helper , auto loading it is best.
#5

[eluser]bretticus[/eluser]
[quote author="Rolly1971" date="1285675956"]try this in your php code:

Code:
$url = base_url() . APPPATH . '/' . 'css/styl.css';

then pass that into your view, and in your css link tag for the soure just use: <?=$url; ?>

don't forget to load the url helper , auto loading it is best.[/quote]

...and make sure that ALL of your code under application/ is locked down as to avoid security breaches! Or just move your browser (client-side) files into the web root where they belong. Smile
#6

[eluser]Rolly1971[/eluser]
bretticus makes a good point. It is a good idea to move your main assets out of the application folder. Always paying attention to security.

if you do move it out of the app folder, just remove the APPPATH . '/' . part o posted above.

i would reccommend creating a folder called: assets - under the root of your site, under there create your css, js, images, and any others you may need, and then for pathing it is much the same as i posted above like this:

$url = base_url() . 'assets/'; for the root assets folder then in your views tag on the remaining parts like 'css/style.css'

this keeps the root assets of your site out of the application or system folders.
#7

[eluser]Niebieszki[/eluser]
my directory structure now is:

Quote:—application
| |—cache
| |—config
| |—controllers
| |—errors
| |—helpers
| |—hooks
| |—language
| |—libraries
| |—models
| |—views
|—css
| |—styl.css
|—system
| |—cache
| |—codeigniter
| |—database
| |—fonts
| |—helpers
| |—language
| |—libraries
| |—logs
| |—plugins
| —scaffolding

when I make this:
Code:
$url = base_url() . 'css/styl.css';
echo $url;

it took:
Code:
href="http://localhost/app/css/styl.css"

and nothing changed. the css style doesn't load
#8

[eluser]victorche[/eluser]
I am more of a html/css/js guy, than a programmer and I really can not understand why everybody here is speaking about echo, asset management library, <?php echo $css; ?>

In my case I have one main template.php file in /views/ folder and my links to the css files are ... how can I say ... hardcoded in this template. The old, normal, working way.

So instead of base_url() and other stuff ... just make one directory in your webroot dir. Call it /theme/ or /assets/ or whatever you like, and put the styles and images there.
and then call it in a normal way, not using C:\XAMPP or http://localhost/...
Use relative paths. This way the application will be more portable. Think how many lines in different files you have to change, when moving to a real hosting/domain. All this "localhost" stuff should be changed then.

What is so hard in adding a simple line in your <head></head> section? Yeah, does not look so ... guru made, programming maniac style, but it works. Try with:
Code:
<link rel="stylesheet" href="/theme/styl.css" type="text/css" media="screen" />
#9

[eluser]Dennis Rasmussen[/eluser]
[quote author="victorche" date="1285691522"]I am more of a html/css/js guy, than a programmer and I really can not understand why everybody here is speaking about echo, asset management library, <?php echo $css; ?>

In my case I have one main template.php file in /views/ folder and my links to the css files are ... how can I say ... hardcoded in this template. The old, normal, working way.

So instead of base_url() and other stuff ... just make one directory in your webroot dir. Call it /theme/ or /assets/ or whatever you like, and put the styles and images there.
and then call it in a normal way, not using C:\XAMPP or http://localhost/...
Use relative paths. This way the application will be more portable. Think how many lines in different files you have to change, when moving to a real hosting/domain. All this "localhost" stuff should be changed then.

What is so hard in adding a simple line in your <head></head> section? Yeah, does not look so ... guru made, programming maniac style, but it works. Try with:
Code:
<link rel="stylesheet" href="/theme/styl.css" type="text/css" media="screen" />
[/quote]
You make no sense.
The point of using base_url() is NOT having to change it everywhere when shipping/moving your application/website since base_url() prints out the domain of your application giving you a dynamic view file.

Hardcoding is what you don't want to do.


Edit: I've got a question related to this post though.
What if you run more than 1 application and need different types of stylesheets (basically any asset file) for each application? Wouldn't that make sense to have this located inside the actual application?
#10

[eluser]victorche[/eluser]
[quote author="Dennis Rasmussen" date="1285699195"]You make no sense.
The point of using base_url() is NOT having to change it everywhere when shipping/moving your application/website since base_url() prints out the domain of your application giving you a dynamic view file.

Hardcoding is what you don't want to do.[/quote]
Sorry, but please read it again :]
It makes perfect sence ... That's the difference between absolute paths and relative ones ;]
With absolute path like:
Code:
href="http://mydomain.com/theme/style.css"
or:
Code:
href="http://localhost/theme/style.css"
Then, yes... Your code will not be mobile at all. You'll have to edit all those paths, everytime you change domain name, or localhost (testing and developing) and real hosting (live site).
But if you use relative paths (the idea of a relative path is to be relative to the webroot directory, meaning "/"), then you'll not have this problem. Like:
Code:
href="/theme/style.css"
In this case, no matter of the domain, server, everything... It will work! Of course, will stop working, if you change the folder structure and rename or move the folder "theme" in this exapmle.
But if you rename/move the folder ... it will stop working with base_url() either. As after this base_url(), you're still adding a static folder as a part of the path.




Theme © iAndrew 2016 - Forum software by © MyBB