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
Related
I have a problem with url in Laravel
<td> Website: {{$data[0]->internet}}</td>
where internet is some website name, for example www.foo.com
The problem is that output URL is http://localhost/www.foo.com instead of http://www.foo.com
change the target attribute target="blank" to target="_blank"
Change your html to
{{$data[0]->internet}}
As stated in the Laravel documentation: https://laravel.com/docs/5.7/urls
The url helper may be used to generate arbitrary URLs for your
application. The generated URL will automatically use the scheme (HTTP
or HTTPS) and host from the current request
$post = App\Post::find(1);
echo url("/posts/{$post->id}");
// http://example.com/posts/1
In your case you won't need the url helper function.
Also make use of the http or https protocol in this format:
http://www.foo.com or https://www.foo.com to make an absolute url instead of a relative one.
Try this way:
{{$data[0]->internet}}
If your variable internet is some website name, for example
www.foo.com and you need to link this URl in anchor tag you dont need
to call this variable inside url() function you can simply use that
variable to link the url in anchor tag.
If you want to get the base URL of your site then you can use url()
fucntion which return base url of your website.
Just replace below line with your code
<td>
Website:
{{$data[0]->internet}}
</td>
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 am new to CodeIgniter and having trouble with link formation. In my page, I have a link to another page set to:
<li>Feed Page</li>
Here the feed is one of my controllers, but the link is showing as:
http://localhost/BusinessPad/localhost/BusinessPad/feed,
which doesn't actually exist. I can't understand how this happened; I have made sure: $config['index_page'] = ''; and I added an .htaccess file. If I leave $config['base_url']='', the base URL is still not working for me.
To deal with anchor tag, You can have like this
Feeds
You shall put the base_url inside your anchor tag and then your controller name.
Then you will get the url like localhost/BusinessPad/feed which you expect.
Note : Make sure you have loaded the url helper by $this->load->helper('url'); or loaded in autoload itself
Feed Page
if this not works use this
Feed Page
Explain :
<?php echo base_url();?>//URL
BusinessPad//Controller
feed//Function
in 1. this will give your site URL. http://localhost/BusinessPad/localhost/. if you host this to live server it will come with tour domain name.
then in 2 it will call your controller which Contains your functions.
Note: if you juct call your controller it will call automatically public function index() if you create.
then in 3 it will redirect to your function which you exactly need.
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()