Why is this link not generated correctly in codeigniter? - php

I'm using codeigniter and the link to my categories don't work right. Maybe I don't understand some settings of the framework. I have in my configuration file set this base url:
$config['base_url'] = 'http://hms.loc';
But when I click the "Home" category or any other category the link looks like:
http://localhost/hms/
But it should be:
http://hms.loc
When I click the "Rooms" category it is:
http://localhost/hms/rooms
How do I set this up correctly? And where can I specify such settings?

You can use base_url() or site_url() method from URL_Helper.
Please check the documentation:
https://www.codeigniter.com/user_guide/helpers/url_helper.html

I use xampp, my web app folder name is "s_v", so i using
$config['base_url'] = 'http://localhost/s_v/';

If your project folder name is hms , define base_url as
$config['base_url'] = 'http://localhost/hms/';
Other wise check in html contain
<base href="http://localhost/hms/">

Related

Paths to differents files in one view - Joomla

I'm trying to put a link in a component's view file (default.php) to another file in the same view (default_formulaire.php) as you can see below:
But I really don't know how to access it in PHP.
I know that the default.php file's url is:
index.php?option=com_multicontact&view=reclamation
but I don't know that of default_formulaire.php.
Thanks for any help :)
The link to any view in Joomla is the following:
index.php?option=com_componentname&view=viewname&layout=layoutname
However, if the layout is omitted from the URL, then it is assumed that it is set to default. So, the following URL:
index.php?option=com_componentname&view=viewname
Will mean that the layout is default, which means that the default.php file will be loaded.
So, in your situation, the URL to load the default_formulaire layout will be:
index.php?option=com_multicontact&view=reclamation&view=default_formulaire
If you need to access a different layout in joomla then you need to add a layout value in joomla url like index.php?option=com_multicontact&view=reclamation&layout=default_formulaire

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 posted double link in address bar when clicking href

help me with this code.
<< Kembali menghitung
when i click the link it posted double like :
http://localhost/belajarci/index.php/calculator/localhost/belajarci/index.php/calculator
ive tried to remove the href values but the page not refered to the home, its only change another value in my code.
It's right it's redirecting on double url becasue of you need to include $this->load->helper('url') in your file / controller constructor or use url helper in autoload.php
Also do two things in your configuration:
Check the .htaccess file in project becasue may be you have set there any url redirect.
Check in config file for base url what you have set there.
You are getting this URL:
http://localhost/belajarci/index.php/calculator/localhost/belajarci/index.php/calculator
Because you need to include $this->load->helper('url') in your file / controller constructor or use url helper in autoload.php
After loading url helper your URL will work as you need.
You can also follow the CI User Manual: https://codeigniter.com/userguide3/helpers/url_helper.html

Base_url() issue with the anchor tag in CodeIgniter

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.

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

Categories