Search code examples
phpcodeignitercodeigniter-routing

Codeigniter routing help, backlinking to previous directories


the site in question is http://www.ziplinegolive.com/

I have built this in CI and currently there is 2 "views" folders

-pages and -news

I want to make a news directory to organize my posts and not have them interfere with the other pages. My problem that im having though is once i enter http://www.ziplinegolive.com/news/home I noticed that when i check my header links...all the urls acquire the news/ directory...which doestn allow me to go back.... does anyone know how i can fix this? i currently have one routes config files and 2 controllers.

first here is my routes.php

$route['news/(:any)'] = 'news/view/$1';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

here is my standard pages controller

<?php

class Pages extends CI_Controller {

public function view($page = 'home')
{
  if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
    // Whoops, we don't have a page for that!
    show_404();
}

$data['title'] = ucfirst($page); // Capitalize the first letter

$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);

}
}

and here is my news controller

<?php
class News extends CI_Controller {

    public function view($page = 'home')
{

    $data['title'] = ucfirst($page); // Capitalize the first letter

  $this->load->view('templates/header', $data);
  $this->load->view('news/'.$page);
  $this->load->view('templates/footer', $data);


}

}

ive been busting my head in to try and figure this out.... any help is GREATLY appreciated!

thank you!

UPDATE: ADDED HEADER.PHP - as you can see the css and js files are static linked because of this routing debacle....

<!doctype html>
<html class="no-js" lang="en">
<head>
 <meta charset="utf-8">
 <title>ZipLine™</title>
 <meta name="apple-mobile-web-app-capable" content="yes">
 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,    user-scalable=no" />
 <meta name="HandheldFriendly" content="true" />
 <meta name="apple-touch-fullscreen" content="yes" />
 <!-- All Animations CSS -->
 <link href="http://www.ziplinegolive.com/css/animate.css" rel="stylesheet" type="text/css">
 <!-- Image Lightbox CSS-->
 <link rel="stylesheet" href="http://www.ziplinegolive.com/css/imagelightbox.css"      type="text/css" media="screen">
 <!-- Theme styles and Menu styles -->
 <link href="http://www.ziplinegolive.com/css/style.css" rel="stylesheet" type="text/css">
 <link href="http://www.ziplinegolive.com/css/mainmenu.css" rel="stylesheet" type="text/css">
 <!-- Call Fontawsome Icon Font from a CDN -->
 <link href="http://netdna.bootstrapcdn.com/font-     awesome/4.1.0/http://www.ziplinegolive.com/css/font-awesome.min.css" rel="stylesheet">
 <link rel="stylesheet" href="js/jquery.fancybox.css" type="text/css" media="screen">

 <!--FlexSlider -->
 <link rel="stylesheet" href="js/woothemes-FlexSlider-06b12f8/flexslider.css"      type="text/css" media="screen">
 <!--Isotope Plugin -->
 <link rel="stylesheet" href="js/isotope/http://www.ziplinegolive.com/css/style.css"      type="text/css" media="screen">
 <!--Simple Text Rotator -->
 <link href="http://www.ziplinegolive.com/css/simpletextrotator.css" rel="stylesheet" type="text/css">
 <!--Modernizer Custom -->
 <script type="text/javascript" src="js/modernizr.custom.48287.js"></script>
 <!-- Fav and touch icons -->
 <link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114-precomposed.png">
 <link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72-precomposed.png">
 <link rel="apple-touch-icon-precomposed" href="apple-touch-fa-57x57-precomposed.png">
 <link rel="shortcut icon" href="favicon.png">
 </head>
 <body class="sticky_header">
 <div class="overflow_wrapper">
 <header>
      <div class="container">
           <div class="logo"><a class="brand" href="index.html"><img      src="http://www.ziplinegolive.com/images/logo.png" alt="optional logo"></a></div>

           <!-- MAIN MENU -->

           <div id="mainmenu" class="menu_container">
                <label class="mobile_collapser">MENU</label>
                <!-- Mobile menu title -->
                <ul>
                     <li class="active"><a href="index.html">Home</a></li>
                     <li><a href="#">About Us</a>
                     <div class="dmui_dropdown_block">
                               <ul class="dmui-submenu">
                                    <li><a href="about">The Company</a></li>
                                    <li><a href="media">Media</a></li>
                                    <li><a href="partners">Partners</a></li>
                               </ul>
                          </div>

                     </li>
                      <li><a href="products">Products and Services</a></li>
                     <li><a href="news">News</a></li>
                     <li><a href="contact">Contact</a></li>
                </ul>
           </div>

           <!-- /MAIN MENU -->

           <div class="triangle-up-left"></div>
           <div class="triangle-up-right"></div>
      </div>
 </header>

Solution

  • Change your links.

    For example

    <li><a href="about">The Company</a></li> 
    => 
    <li><a href="<?php echo site_url('about');?>">The Company</a></li>
    

    And also, you can link to css/js files like this:

     <link href="<?php echo base_url('assets');?>/css/mainmenu.css" rel="stylesheet" type="text/css">
    

    This of course expects that you have your css files in project/assets/css