All links in codeigniter are maintaining old segments - why? - php

If you link off the homepage it works. So www.domain.com goes to www.domain.com/parent1/mypage.php but then when I link to the next page it keeps the first segment/parent (right word?) so the link becomes www.domain.com/parent1/parent2/anotherpage.php and so on.
After three clicks we have www.domain.com/parent1/parent2/parent3/third.php. Any idea where I did something wrong. This is also affecting images and all images are appearing as if they are in the category www.domain.com/parent1/images/image.jpg - not sure what the parent1 is there.
I hope that made sense. I am really in trouble here. Any help?

You either want to use base_url as Robert has suggested like this:
Post 123
or you can use site_url() like this:
Post 123
or if you can use the anchor() tag like this:
<?php echo anchor("blog/post/123", "Post 123"); ?>

You're (probably) using relative URI's instead of absolute, that's what is messing it up.
When creating links, it's recommended to use base_url function like this:
echo base_url("blog/post/123");
if you're using it inside a HTML template, just add PHP tags:
<?php echo base_url("blog/post/123"); ?>
You can also use it like this:
Post 123

Related

a href refers to site itself + link instead of the link itself

In Codeigniter, I have a database containing a link of a site.
Each item(event) has a link to the event page.
Site
But instead of going to the desired site, it just adds the link to the existing url like this: http://web.site.local/index.php/evenementen/www.referedsite.com
when checking the html code it shows the following:
Site
Does anyone know how to make it go to www.referedsite.com instead of making it add this to the existing link?
You need to put HTTP://
Site
In codeignitor you can use
echo anchor('', 'Site');
// Prints: Site
Read CI Anchor
try
Site

PHP Pagination different page call

i use php code for call page using url like this
Home
News
Event
etc...
many sample pagination using url
href="news.php?page=$pageno"
my question is how to make link url pagination if using url like
href="?page=news"
i have try using this code
<a href=?page=news?page=$i>$i</a>
but not work, Please help??
i am newbie on php
I think your question is a bit blurry, but try to figure out the logic using the following rudimental code.
In the page where you place your links, enter this:
1
In your news.php:
<?php
if ($_GET['page']) {
// do stuff with $_GET['page'], which is '1' in this case.
}
?>
In this example, $_GET['page'] will evaluate to the number 1. This variable can then be used to include the news you want to display, be it through including another php-page, or by calling a set of articles from a database.
Don't forget to put <?php and ?> tags around the code, otherwise things won't work.

Iframe URL - PHP or Javascript?

I'm trying to build a custom top toolbar which an iframe below it.
Something similar to this:
http://themes.goodlayers.com/?theme=greenearth
I plan one using it on a blog, so i will be making posts linking to other sites. My question is what do i need to make a custom url function that so i just add it in front of the other site's url so that it shows up in an iframe.
For example:
I want to link to google in an iframe with my top toolbar above.
Is there a script that allows me to use a url like this:
http://www.mywebsite.com/frame.php?http://www.google.com/
Thanks for your time!
Iframes are always bad. Don't do it.
That said, with PHP, you can do this:
<iframe src="<? echo $_SERVER['QUERY_STRING'] ?>" />
You can also do something like mywebsite.com?url=google.com, and use $_GET['url'] instead.
Eg url: http://mywebsite.com/index.php?iframe=http://www.google.ro
PHP:
<?php
if ($_GET['iframe']) {
echo"<iframe src='".$_GET['iframe']"' width='200px' height='150px'>";
} ?>
I hope this will help you!

Anchor to a section with CodeIgniter

i'm trying to create an anchor to a page's element. There's a tab interface. In html i can see that their links are like this:
http://example.com/index.php/service#tab-1
http://example.com/index.php/service#tab-2
http://example.com/index.php/service#tab-3
http://example.com/index.php/service#tab-4
So that i have 4 div's with id's tab-1,tab-2 etc.
How can i create anchor to them from another view file? When i try this:
give it a try
it goes to page /service but not focused on #tab-1 . It was working on plain html, but i couldnt do it with codeigniter
Thanks for help!
I just tried the same thing on my CodeIgniter and it worked fine so I suggest double checking your IDs are correct. Other than that try
give it a try
or
give it a try
You need to put the target of #tab-1 etc. in your page. So in your div you need to include a named anchor such as:
<a name="tab-1"></>
This will cause the page to jump to this element.

Adding a page link in CakePHP

I'm trying to add a page link in CakePHP using:
<?php echo $html->link('Home', '/notes/index');?>
It doesn't seem to output the proper link.
What I'd want is something like this:
Home
How can I do this?
You'll want to use a url array
<?php echo $html->link('Home', array('controller'=>'notes','action'=>'index')); ?>
This will work for you. You will not be able to use an absolute path :)
Check out the manual page, http://api.cakephp.org/class/html-helper#method-HtmlHelperlink
Create individual controller for this page or create routing for this page in PagesController.

Categories