1

i spend my hours to solve this problem but cannot reach anything.I applied what said in stackoverflow but it does not work.

As you see below my css files are stores in public directory and try to use anasayfa.css

enter image description here

and try to reach my css files with my view. but does not work. enter image description here

i also remove my index.php with htaccess my in rule in htaccess i allowed css files like that

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteRule ^(.*)$ /pasaj/index.php/$1 [L]

How can i reach my css ? what's the problem?

3 Answers 3

2

What's the "Pasaj - El emegi.." ? Is it the page title? why is there inside an url?

It should be (absoluth url):

<link rel="stylesheet" href="/public/css/anasayfa/anasayfa.css"/>

Or, much easier, using base_url() (url helper):

<link rel="stylesheet" href="<?php echo base_url();?>public/css/anasayfa....">

Or with link_tag() (html helper):

<?php echo link_tag('public/css/anasayfa...');?>

UPDATE:

to load an helper, put inside the controller's method you're using to call that view:

$this->load->helper('url');

Refer to the manual for this and other basic infos: it's pretty extensive and clear, it will answer many of your doubts

Sign up to request clarification or add additional context in comments.

2 Comments

Be sure you load/autoload urlhelper if you use it in a link tag like that as many browsers wont print any sensible error information if you forgot to load the helper.
<link rel="stylesheet" href="<?php echo base_url();?>public/css/anasayfa/anasayfa.css"> i put this.The result is empty page..
1

Your CSS files SHOULD NOT BE in your views folder, never.

That said from what I see they are not, they are in a public folder at the root ?

So then you need to change your link to

/public/css/...

in place of

/views/public/css/...

Comments

1

you are using relative URLs. the base url of CodeIgniter is mysite.com/index.php. so that means your <link> is looking for it in mysite.com/index.php/views/public/css... - it treats it like another page, with views as controller, public as method and the rest as parameters.

the shortcut method is to prepend a / to your link url (to tell it to start from the root)

the longcut method is to prepend base_url() to your view/template before it is passed on to the browser for rendering

2 Comments

I won't downvote but a bit wrong information here. Base url is the url which you define in config page. In most cases, it is better to leave it as mysite.com. Hence, its not necessarily will output mysite.com/index.php. What you mentioned is actually the site url(which again can be configured).
i actually meant base_url. This function returns the same thing as site_url, without the index_page or url_suffix being appended - which means it's like starting off from root

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.