Let I am in following location
http://localhost/ignitershop/index.php/seller_controller/viewcart
And here in this view I have a link and using it i want to move to another method of the same controller called removeRow() . So I am using href as below
<a href="seller_controller/removeRow" >CLICK TO REMOVE </a>
So I expect the new url to be :
http://localhost/ignitershop/index.php/seller_controller/removeRow
but the url seems to be concatenating. And it is becoming something as below :
http://localhost/ignitershop/index.php/seller_controller/seller_controller/removeRow
That is seller_controller is coming twice. I am facing such type of concatening problem using redirect also. So I need to know what it is the best way for switching method of the same controller. Any good solution ???
Try like
<a href="<?php echo site_url('seller_controller/removeRow');?>" >CLICK TO REMOVE </a>
Or you can also try like
<a href="<?php echo site_url().'seller_controller/removeRow';?>" >CLICK TO REMOVE </a>
You cont use base_url() Because it doesnt included the index page (May be the index.php ) where site_url() has the combination with base_url() and index url.
Use ob_start(); at the begging of the script.
This is happening, because your link is relative - i.e. it is added to the current URI minus the last part. Think of it like directories and files - the last part (viewcart) is a file, and the rest is a directory. A relative link means "Hey, take me to this file (removeRow), but start delving from the current directory".
This means that if you have http://localhost/ignitershop/index.php/seller_controller/viewcart and there you visit a link with content Link, it will send you to http://localhost/ignitershop/index.php/seller_controller/one/two/three
To fix it, use base_url() or site_url() functions from the URL helper accordingly, which will do the job for you. Check out the documentation for more info.
Try to use the absolute path by using either site_url() or base_url()
Related
i am trying to make the URL in my PHP application cleaner using htaccess. Earlier the links of my application were in this format
http://localhost/25_2_april/video.php?cat_id=2&category=Programming-Language, but with the help of htaccess i was able to convert it into
http://localhost/25_2_april/video-library/2/Programming-Language. Now ,the question is that every time i run my application it loads the messy URL instead of the clean URL , although when i edit the url ,and make it clean url, then that works too. Now is there any way, that it directly loads the clean url instead of the messy url.
Below is the anchor tag through which i am calling this particular page.
<a href="<?php echo 'video.php?cat_id='.$cat_id.'&category='.$cat_name; ?>">
As you are adding static URL in html so must have to pass your clean URL as :
<a href="<?php echo 'http://localhost/25_2_april/video-library/'.$cat_id.'/'.$cat_name; ">
this is my code below.
<li>Why share?</li><li>
But after I apply this i manage to redirect to the page but when i try to press another page the url will be keep adding like this and cause page not found.
The page look like this
But when i try to link to home page, the url won't change back to /home only
Any solution? or another way to link the page?
Need help on this!
Thanks!
Your href should have a slash in front of it so that it goes to "root".
<li>Why share?</li><li>
If not, the browser will think it is relative to the current route. Or use Codeigniter's built-in site_url() function
<li>Why share?</li>
Read about relative/absolute here: http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/
You need to set your base_url() in config.php, and call the url_helper so that you can then use it.
Step by Step Instructions:
in application/config/config.php, set your base_url, I prefer to use something like this:
$config['base_url'] = 'http://' . $_SERVER['SERVER_NAME'] . '/';
in application/config/autoload.php, add url helper:
$autoload['helper'] = array('url');
Use it in your views like this:
<a href="<?= base_url('about/why') ?>" > link </a>
Read this: https://www.codeigniter.com/user_guide/helpers/url_helper.html
Good Day! I've got some trouble on PHP. If I click an href which is this <a href = 'members/loans/loan-application-form.php'> it goes to the loan-applicaton-form.php, but if i click it again inside the loan-application-form.php (cuz it is located at the navbar that exist in all pages) the href of the anchor concatenates on the existing url and it creates an error telling that address is not existing. I already knew that the problem is it searches the address on the current directory and probably it will return an error because there is no existing address on the directory because it is the origin or the parent. What is the best way to avoid this?
Add a base tag to your header. This will prepend all HTML URL's with the given base URL. (Including images, CSS and JS calls)
<head>
<base href="http://www.yourdefaulturl.com/">
</head>
Your URL will then be http://www.yourdefaulturl.com/members/loans/loan-application-form.php
You can use an absolute path
<a href = 'http//your.site.cpm/members/loans/loan-application-form.php'>
Advice : you can read this article
or this stack question
Or you can use ../ to navigate inside your relative path
Lets imagine your nav bar is located at /navigation/navbar.html
Then you can have a relative path like
<a href = '../members/loans/loan-application-form.php'>
By specifying relative Urls like so:
<a href = 'members/loans/loan-application-form.php'>
You are simply stating you wish to go form the current page to this page, hence why it is being added to the end of the current URL. The best way to avoid this quite simply is to set an absolute URL like so:
<a href = 'http://projectname/members/loans/loan-application-form.php'>
Even when not using http:// it is often still considered relative so be sure to include this.
Another way to do the same but slightly quicker would be to add a variable in say your header file for example:
$url = 'http://example.com';
Then when specifying the URLs you can do say:
<a href = '<?php echo $url;?>/members/loans/loan-application-form.php'>
This just means that should you say change your domain, rather than editing every URL you can simply edit the variable value and be done with it.
i'm having an problem with the URL of Codeigniter.
When i use one controller with parameter, example: localhost/ci/products/news (where localhost/ci is the url base), after i click in any element <a />, example: <a href="home"/> Codeigniter redirects for localhost/ci/products/home and no for localhost/ci/home.
Anyone know why this happens?
You must use a base_url for links. Right now your anchor has a relative path in the href="home", you should have full path in your links, when u use mod_rewrite for nice urls.
like
Home
I am trying to use an image as a button to refresh pages on a website. The footer (a php include) is currently using this code to refresh each page:
<img src="/images/refresh.png">
which of course works. BUT I would like to improve it. Essentially, it would be something like this:
onClick="javascript: window.location.href='abcd.html';"
BUT I need it to work dynamically because I'm using php pages. So I was thinking this would work:
<img src="/images/refresh.png">
But it doesn't work. Any ideas? I'm using <? php $_SERVER['REQUEST_URI'] ?> wrong (obviously), so, any ideas for assistance? Thank you for any help!
Problem noticed is you have a space between <? and php in the following line:
<img src="/images/refresh.png">
Also you want to echo out the value for $_SERVER['REQUEST_URI']. You are just calling $_SERVER['REQUEST_URI']. Also as #NickCoons pointed out when using the echo construct you need to add a semi-colon i.e. echo $_SERVER['REQUEST_URI'];.
Try the following:
<img src="/images/refresh.png">