CodeIgniter Forums
Linking to Stylesheets - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Linking to Stylesheets (/showthread.php?tid=34089)

Pages: 1 2


Linking to Stylesheets - El Forum - 09-18-2010

[eluser]pbreit[/eluser]
Try to do what WanWizard suggests.


Linking to Stylesheets - El Forum - 09-19-2010

[eluser]mi6crazyheart[/eluser]
[quote author="Praveen A P" date="1284875011"][quote author="WanWizard" date="1284862610"]Move your application directory out of the system directory, and move your assets out of your application directory.

Most people use a /assets directory, in there you can create /css, /js and so on. You then create links like this:
Code:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/defaultStyle.css"/>

which makes them independent of your application directory, and because you no longer hardcode your url's, fully portable.[/quote]


Tried the base url thing which did not work. Let me try the other part.[/quote]

Have u config u'r base url properly from u'r config.php file... ?


Linking to Stylesheets - El Forum - 09-20-2010

[eluser]daniel9201[/eluser]
try this
in your config.php

$config['css_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['css_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/css/';

specify the location of the css directory relative to the application root

in your view

<head>
<title>Sample Page</title>

<link rel="stylesheet" type="text/css" href="<?php echo $this->config->item('css_url') . 'mystyles.css'; ?>" media="screen" />



</head>

another handy trick is to use

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/index.php/';

in the config.php so you can rename your root application folder to whatever you want and just rename or move the whole folder and you application will pick up the new location.

it does mean if your using forms you have to use something like

<?php
$my_base = base_url();
//$my_action = $my_base . "site/processlistedit";
$my_action = $my_base . "site/messages/edit/" . $id;
echo "<form method='post' action= $my_action />";
?>

// End of table
<tr><td>&lt;input type="submit" value="Submit" /&gt;&lt;/td></tr>
</table>
&lt;/form&gt;

&lt;?php
$my_base = base_url();
$my_action = $my_base . 'site/' . $myaction1;
echo "<br/>";
echo "<br/>";
echo "<a href=" . $my_action . " title='Home'>Click Here to return</a>";
?&gt;

it works for me but if you have a better way let us know.


Linking to Stylesheets - El Forum - 09-20-2010

[eluser]Vega[/eluser]
You could use link_tag(): http://ellislab.com/codeigniter/user-guide/helpers/html_helper.html#link_tag


Linking to Stylesheets - El Forum - 09-22-2010

[eluser]Praveen A P[/eluser]
Thanks alot guys for the help.