How can auto add .html in last url with Codeigniter - php

i'm using Codeigniter for my website. I had add url_suffix in config
$config['url_suffix'] = '.html';
Normal i create $href with same below code
echo "<li>Products</li>";
I must add .html in last. How can i auto add .html in url but i don't need fill it in last

You should use site_url()
Your href should look like this site_url('controller/method');

You should use site_url() function for auto generate of URL in codeigniter
Use this:
echo "<li>Products</li>";
Instead:
echo "<li>Products</li>";

Related

How to add index.php in base_url() in codeigniter

In general when we use site_url() in anchor tag in php code it auto insert "index.php" before the controller like
/index.php/controllerName/methodName
But in base_url it doesn't insert "index.php".
I want to add auto index.php before the controller how site_url() works.
Already I searched and understood that the change will be in config file.
But want to know the specific answer what I need to change.
Base URL should be absolute, including the protocol:
$config['base_url'] = "http://somesite.com/somedir/";
If using the URL helper, then base_url() will output the above string.
Passing arguments to base_url() or site_url() will result in the following
$config['index_page'] = "index.php";:
echo base_url('assets/stylesheet.css'); // http://somesite.com/somedir/assets/stylesheet.css
echo site_url('mycontroller/mymethod'); // http://somesite.com/somedir/index.php/mycontroller/mymethod

Codeigniter URL Overlapping. Not working properly

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

CodeIgniter URL suffix .html automatically for all URL

I am new in CodeIgniter.
I setup CI in my localhost Eg. localhost/MyProjects/CodeIgniter/welcome/index
I can able to remove the index.php from the url & I also completed the .html suffix
So, I can able to visit localhost/MyProjects/CodeIgniter/welcome/index.html & Its working properly.
So I am using my a tag like this:
Register
But, I dont want to use the .html in my link manually.
have any solution to show my visitor .html suffix automatically Eg. localhost/MyProjects/CodeIgniter/welcome/index.html Or localhost/MyProjects/CodeIgniter/welcome/about.html Etc
Here is my htaccess http://pastebin.com/cXUFjvbp
Just edit url_suffix in config.php .....
$config['url_suffix'] = '.html';
Use site_url()
<!-- No need .html -->
Register
<!-- Register -->
Or anchor()
// No need .html
echo anchor('welcome/register', 'Register');
// Register
Note : Dont forget to load URL helper with $this->load->helper('url');.
Change your config.php file
$config['url_suffix'] = '.html';
Just redefine the base_url function or make a new one. Look at the source of base_url method
function _base_url($path = NULL) {
return base_url() . $path . '.html';
}

codeIgniter base url issue

Hi i am new in codeigniter, having trouble with link formation. In my page i have link to another page same to <li>Feed Page</li>
here feed is one of my controller . But the link is showing to me as http://localhost/BusinessPad/localhost/BusinessPad/feed ---that actually doesn't exists. Can't understand how this happen. I have make $config['index_page'] = ''; and add a .htaccess file.
check for value you have assigned to base_url in you config.php file ,try site_url(), change:
<?php base_url('feed');?>
to
<?php echo site_url('feed'); ?>
you can create your own tag and insert a url in the href like this
Link
Or if you want to helper
you can use the URL helper this way to generate an tag
anchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('controller/function/uri', 'Link', 'class="link-class"') ?>
use this:-
Link
or
Link
or
Link
use this way
Feed Page
or
Feed Page

codeigniter: why is that when i echo base_url() in an href attribute of an anchor tag, it echoes twice

so basically when i echo the codeigniter function base_url() in the href attribute of an anchor tag, it appears to echo it out twice. Example:
somelink
and the above, if you inspect it your chrome browser shows this:
somelink
"mysitedomainname.com" is just a name i made up for this example. Any reason why this is happening?
There are three reasons I'm aware about that can cause this.
The first one is when something wrong is written in config.php on line 17 $config['base_url'] = ''; - it better be left empty, just like when you download CI.
The second one is if you have set $config['base_url'] value to something without prefixing it with http:// or other protocol.
The third one is if you have set base href somewhere:
<base href="http://www.mysitedomainname.com/" />
When you need to link to some other page, you should use site_url(), base_url() can be used to link stylesheets, js, img src attributes and other real URL's. The reason is pretty simple, base_url() does not include the index_page value set in config.php.
try this
make this
$config['base_url'] = "http://www.mysitedomainname.com"
into this
$config['base_url'] = ""
in config.php
It will work fine if you use
somelink

Categories