Welcome Guest, Not a member yet? Register   Sign In
using pagination breaks links to styles [SOLVED]
#1

[eluser]artificialkid[/eluser]
Hy guys,

I´m building my first site with CI, on each page I load parts of the webpages:

1.header view(doctype, styles, javascript)

2.content of each page

3.footer view

All as going well until my Diary page (like a blog) were I use pagination to navigate between chuncks of articles, the problem happens when i click on one of the pagination links, the page loads good, but without styles or javascripts tags

the url on diary page is http://localhost/~faustopacheco/code/diary (all shows well)

clicking on one pagination link is http://localhost/~faustopacheco/code/diary/index/2

the error is

Code:
Error: The stylesheet http://localhost/~faustopacheco/code/diary/index/css/styles.css was not loaded because its MIME type, "text/html", is not "text/css".
Source File: http://localhost/~faustopacheco/code/diary/index/2
Line: 0

-------------
Error: syntax error
Source File: http://localhost/~faustopacheco/code/diary/index/js/jquery-1.2.min.js
Line: 1
Source Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-----
Error: syntax error
Source File: http://localhost/~faustopacheco/code/diary/index/js/functions.js
Line: 1
Source Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

my Diary controller

Code:
&lt;?php

class Diary extends Controller {

    function __construct()
    {
        parent::Controller();
        $this->load->model('diary_model');    
    }
    
    function index()
    {
        
        // load pagination class
        $this->load->library('pagination');
        $config['base_url'] = base_url().'/diary/index';
        $config['total_rows'] = $this->db->count_all('articles');
        $config['per_page'] = '2';
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $config['cur_tag_open'] = '<em>';
        $config['cur_tag_close'] = '</em>';

        $this->pagination->initialize($config);
        
        //load the model and get results
        //$this->load->model('books_model');
        $data['results'] = $this->diary_model->get_articles($config['per_page'],$this->uri->segment(3));
        // load the HTML Table Class
        $this->load->library('table');
        $this->table->set_heading('id', 'title', 'date', 'text','image');
        
        
        $this->view->part('header', 'header/header_view');
        $this->view->part('footer', 'footer/footer');
        
        $this->view->load('diary_view',$data);
        

    }
    

}
?&gt;

the view:

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


<div id="mainContent">
    
    <h2>diary.</h2>

    &lt;?php echo $this->pagination->create_links(); ?&gt;
    &lt;?php echo $this->table->generate($results); ?&gt;
    &lt;?php echo $this->pagination->create_links(); ?&gt;



    </div>




&lt;?php echo $footer;?&gt;

the header view:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
    &lt;meta name="Keywords" content="design, webdesign, web 2.0, inspiration, photography, beautiful, lisbon, sun, food, gourmet" /&gt;
    &lt;meta name="description" content="Hand crafted pixels and food." /&gt;
&lt;title&gt;The countryside isforcows - &lt;?php echo$this->uri->segment(1); ?&gt;&lt;/title&gt;
&lt;?php echo $this->config->item('css');?&gt;
&lt;?php echo $this->config->item('js');?&gt;  
&lt;?php echo $this->config->item('jsfunctions');?&gt;  
  &lt;/head&gt;
  &lt;body&gt;
    <div id="wrapper">
      <div id="header">
        <h1><span>The countryside isforcows</span></h1>
        <div id="navigation">
          <ol>
                <li><a &lt;?php if($this->uri->segment(1) =='welcome' || $this->uri->segment(1) =='' ){echo "id='current'";}?&gt; href="welcome" title="welcome">welcome</a></li>
                <li><a &lt;?php if($this->uri->segment(1) =='about'){echo "id='current'";}?&gt; href="about" title="about me">about</a></li>
            
            <li><a href="[removed]void(0);" title="services">solutions</a></li>
            <li><a &lt;?php if($this->uri->segment(1) =='work'){echo "id='current'";}?&gt; href="work" title="portfolio">work</a></li>
            <li><a href="[removed]void(0);" title="contact">contact</a></li>
          </ol>
        </div>
    </div> &lt;!-- end header --&gt;

is the page breaking because loading views into views?
#2

[eluser]Jim OHalloran[/eluser]
[quote author="luckylisbon" date="1190858025"]the header view:

Code:
&lt;?php echo $this->config->item('css');?&gt;
&lt;?php echo $this->config->item('js');?&gt;  
&lt;?php echo $this->config->item('jsfunctions');?&gt;

is the page breaking because loading views into views?[/quote]

You hven't shown us the config values for the CSS, Js, etc, but I'm guessing they're something like "../css/styles.css"...

What's happening is that the relative path breaks as you add more segments to the URL. The easiest fix is to use the URL helper, and change your code to something like this:

Code:
&lt;?php echo base_url() . $this->config->item('css');?&gt;
&lt;?php echo base_url() . $this->config->item('js');?&gt;  
&lt;?php echo base_url() . $this->config->item('jsfunctions');?&gt;

Then change your configuration files and remove the so that the CSS (and javascript, etc) is referenced as "css/styles.css". More information about why this happens can be found here and here.

Jim.
#3

[eluser]artificialkid[/eluser]
Tank you.

Smile




Theme © iAndrew 2016 - Forum software by © MyBB