SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question One path, but hide link per page is different

    I have a menu like this, its in header.php (I else footer.php):

    PHP Code:
    <div id="menu">
       <
    ul>                                                                       
           <
    li class="selected hover"><a href="user/welcome">Home</a></li>
           <
    li class="hover"><a href="user/about">About</a></li>
           <
    li class="hover"><a href="user/specials">Specials</a></li>
           <
    li class="hover"><a href="user/account">Account</a></li>
           <
    li class="hover"><a href="user/register">Register</a></li>
           <
    li class="hover"><a href="user/price">Price</a></li>
           <
    li class="hover"><a href="user/contact">Contact</a></li>
       </
    ul>
    </
    div> <!-- end .menu --> 
    In the home page (index.php), I include header.php and footer.php into one, and menu above works normal. But, when I click About link or other link (sure header.php and footer.php is included), in the about page, hover About, Specials ... I receive some hide link (or url) like http://localhost/demo/foods/user/user/about, http://localhost/demo/foods/user/user/specials. I don't want to them, I want http://localhost/demo/foods/user/about ..., css and jquery are not working too. Have anyone know why? Thank you!

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,112
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    It would be better for your links to have a root relative URL so that the links don't break, because they are relative to the current page location at the moment, so if you hover one of those links on a page that is already in the /uers/ directory, you'll get the URLs you posted above, which is wrong. Something like this would be better:

    <a href="/demo/foods/user/about">About</a>

    But that will only work if you have a local server environment set up. It will also break things when you put this code online. So when building locally, it's better to set up your local environment to reflect the online environment by modifying your hosts file.

    It's also ver inefficient to have the "hover" class on each LI like that. It would be better to target those LIs with #menu li instead, and not use the hover class at all.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    It would be better for your links to have a root relative URL so that the links don't break, because they are relative to the current page location at the moment, so if you hover one of those links on a page that is already in the /uers/ directory, you'll get the URLs you posted above, which is wrong. Something like this would be better:

    <a href="/demo/foods/user/about">About</a>

    But that will only work if you have a local server environment set up. It will also break things when you put this code online. So when building locally, it's better to set up your local environment to reflect the online environment by modifying your hosts file.

    It's also ver inefficient to have the "hover" class on each LI like that. It would be better to target those LIs with #menu li instead, and not use the hover class at all.
    Can you resolve that problem with CodeIgniter? I see the same problem with CI.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,112
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    I would presume so, but I don't know it well enough. You might need to give us some more information about your setup.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  5. #5
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    I would presume so, but I don't know it well enough. You might need to give us some more information about your setup.
    I give some information about project without CI, here is my .htaccess:
    PHP Code:
    RewriteEngine On

    RewriteCond 
    %{REQUEST_FILENAME} !-d
    RewriteCond 
    %{REQUEST_FILENAME} !-f
    RewriteCond 
    %{REQUEST_FILENAME} !-l

    RewriteRule 
    ^(.+)$ index.php?url=$[QSA,L]

    ErrorDocument 404 /view/shared/error/404.php 
    index.php
    PHP Code:
    <?php
        
    require_once 'core/loader.php';
        require_once 
    'core/controller.php';
        
        
    $loader = new loader($_GET['url']);
        
    $controller controller::getInstance($loader->controller$loader->action);
        
        include 
    "view/user/include/header.php";
        
    $controller->request();
        
    $controller->render();
        include 
    "view/user/include/footer.php";
    ?>
    url's form: localhost/dpfoods/controller_name/method_name?id=
    I take controller_name, method_name by explode function and pass them to loader class. The loader class will select controller and then controller will select function.

    in index.php (default page, menu above displays normal):
    // main menu
    Home >> About >> ...
    Home - localhost/dpfoods/user/welcome
    About - localhost/dpfoods/user/about

    but in other page, apple details page example:
    // main menu
    Home >> About >> ...
    Home - localhost/dpfoods/user/user/welcome
    About - localhost/dpfoods/user/user/about

    // other menu
    Home >> Fruits and vegetables >> apple
    if true:
    Home - localhost/dpfoods/user/welcome
    Fruits and vegetables - localhost/dpfoods/user/category?id-category=4
    apple - localhost/dpfoods/user/details?id-product=25
    // but all hide links in this menu are the same
    localhost/dpfoods/user/details?id-product=25
    Structure folder:
    28701044.png

  6. #6
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This is a problem that has been bugging me for years and I solved it site by site. Now I've come up with a generic solution which works on my LAMP server as well as on OSX. I would be interested to know if it works in other environments.
    PHP Code:
    <?php

    function offset2root() {

        
    $phpSelf explode('/'$_SERVER['PHP_SELF']);
        
    $scriptFilename explode('/'$_SERVER['SCRIPT_FILENAME']);
        
    $root array_intersect($phpSelf$scriptFilename);
        
    $count count($root);
        
    $offset '';
        while (
    $count-- > 2) {
            
    $offset .= '../';
        }
        if(empty(
    $offset)) {
            return 
    './';
        } else {
            return 
    $offset;
        }

    }

    $offset offset2root();

    echo 
    "<a href='{$offset}path/to/file.php'>file.php</a>";

    ?>
    Denny Schlesinger
    web services

  7. #7
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @captainccs I work on XAMPP server as well as on Windows 8. Look again my index.php:
    PHP Code:
    <?php 
        
    require_once 'core/loader.php'
        require_once 
    'core/controller.php'
         
        
    $loader = new loader($_GET['url']); 
        
    $controller controller::getInstance($loader->controller$loader->action); 
         
        include 
    "view/user/include/header.php"
        
    $controller->request(); 
        
    $controller->render(); 
        include 
    "view/user/include/footer.php"
    ?>
    and my url form: localhost/dpfoods/controller_name/method_name?id=. The fisrt thing, header and footer is always putted on index file (see my structure folder), if I remove controller_name in url, it's mean url's form: localhost/dpfoods/method_name?id= and have no problem. Contrary, If I don't remove controller_name and then when I click link about, contact ... (not home), css and image path doesn't work. What's difference?


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •