Welcome Guest, Not a member yet? Register   Sign In
Problem linking the style sheet
#1

[eluser]stormlead[/eluser]
I have just created a simple page to start with. I wrote code as following:

in config file:
$config['base_url'] = "http://localhost/CodeIgniter_1.7.2/";
$config['css'] = "mystyle.css";
$config['index_page'] = "index.php";

then through routes file i call the welcome.php page which is as follows
Code:
I have just created a simple page to start with. I wrote code as following:

in config file:
$config['base_url']    = "http://localhost/CodeIgniter_1.7.2/";
$config['css'] = "mystyle.css";
$config['index_page'] = "index.php";

then through routes file i call the welcome.php page which is as follows
<?php

class Welcome extends Controller {
var $base;
var $css;

function Welcome()
{
     parent::Controller();    
}
    
function index()
{
     $base=$this->config->item('base_url');
     $css=$this->config->item('css');
    $data['css']=$this->css;
    $data['base']=$this->base;
    $data['mytitle']='Welcome to my first page';  
     $data['mytext']='Ok! So i am getting a hang of CI. Its good lets just move on...';  
    $this->load->view('index',$data);
    }

}
and finally with the index.php file
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;This is test page&lt;/title&gt;
&lt;link rel="stylesheet" type="text/css" href=&lt;?php echo "$base/$css";?&gt;" /&gt;
&lt;/head&gt;
&lt;body bgcolor="#CCCCCC"&gt;
<div align="center" class="style1" >
This is my test page </div><br />
<div align="center" class="style2" >
&lt;?php echo "$mytitle";?&gt;
</div><br />
<div align="center" class="style3" >
&lt;?php echo "$mytext";?&gt;
</div><br />
&lt;/body&gt;
&lt;/html&gt;

also i have put the mystyle.css in
CodeIgniter_1.7.2
folder.
also i tried to put the mystyle.css in the views and other ways. but still the styles is not getting loaded. and output is plain default text.
Can any one please HELP
#2

[eluser]Niraj Dave[/eluser]
i am not sure but try


Code:
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo $base.'/'.$css;?&gt;" /&gt;
or
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo $base.$css;?&gt;" /&gt;
#3

[eluser]Phil Sturgeon[/eluser]
This a slightly over the top way of handling it. You don't need to output the base URL in front of it all as you can set that once in the header. Take a look at my "Asset handling in CodeIgniter with the BASE tag".
#4

[eluser]stormlead[/eluser]
@NIRAJ
i tried the way u showed but still not working the same output i am getting
#5

[eluser]stormlead[/eluser]
@phil
Thanks alot. Your way was usefull and i got the problem solved.
#6

[eluser]Niraj Dave[/eluser]
try

in config
change
Code:
$config['base_url']    = "http://localhost";
in controller
Code:
function index()
    {
    $base = $this->config->item('base_url');
    $css = $this->config->item('css');
    
    $data['css']=$css;
        $data['base']=$base;
        $data['mytitle']='Welcome to my first page';  
        $data['mytext']='Ok! So i am getting a hang of CI. Its good lets just move on';
    
        $this->load->view('index',$data);
      //$this->load->view('welcome_message');
    }

in view file

Code:
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo $base."/".$css;?&gt;" /&gt;

and use

Code:
&lt;?php echo $mytitle;?&gt;

instedof
Code:
&lt;?php echo "$mytitle";?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB