Search code examples
phpcodeigniterdynamichref

about php dynamic link <a href=""></a>


Hello stackoverflow users,

My problem is about php dynamic link creation.

I try to create dynamic link like;

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="tr" xml:lang="tr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9" />
        <title>Dilşad Çiçekçilik</title>    

        <script type="text/javascript" src="yoxview/yoxview-init.js"></script>

    </head>
    <body>
        <div class="yoxview">
          <?php 

          ...

          for($i=0;$i<$images->num_rows();$i++) {
              echo "<a href='".$imagesArr[$i]."' ><img src='".$thumbsArr[$i]."' /></a>";
          } 

          ....

          ?>
          <?php echo $this->pagination->create_links(); ?>
        </div>
    </body>
</html>

my problem start from the line;

echo "<a href='".$imagesArr[$i]."' ><img src='".$thumbsArr[$i]."' /></a>";


$imagesArr[$i] contains the url -->"yoxview/gallery/sevgiliye/images/anneye10.jpg"

$thumbsArr[$i] contains the url -->"yoxview/gallery/sevgiliye/thumbs/anneye10.jpg"

But, generated html page created to link like this:

.http://localhost/codeigniter/galleryController/index/yoxview/gallery/sevgiliye/images/anneye10.jpg

.http://localhost/codeigniter/galleryController/index/yoxview/gallery/sevgiliye/thumbs/anneye10.jpg

my controller name "galleryController" and my function name "index" and other base url are adding before the href link.

I want to created link which contains only

yoxview/gallery/sevgiliye/images/anneye10.jpg

this url.

How can i achive this ?

Thank you.


Solution

  • This has nothing to do really with your code, and is a function of how browsers process non-absolute urls. You've not put a / or http://example.com/path/to/page type "root" on your urls, so the browser is taking the address of the page as it sees it (http://localhosthost/codeignitre/galleryController/index) and adding that to your non-absolute urls.

    You'll have to use /yoxwview/gallery/etc... instead (assuming that's a valid path on your server).