Codeigniter: error in base_url - codeigniter

i have one problem with function base_url() in my codeigniter.
I'm configure the condeigniter to:
$config['base_url'] = 'sistema_clientes/';
$config['index_page'] = '';
and autoload to:
$autoload['helper'] = array('url');
It's ok, but when i'm try to use base_url('clientes') in my pages, the link repeat.
example, i wanna this : localhost/sistema_clientes/example.
<li>Example</li>
in my url, the link go to: http://localhost/sistema_clientes/sistema_clientes/clientes
but i wanna this: http://localhost/sistema_clientes/clientes
i don't wanna the base_url() repeat the sistema_clientes, please help me.
what i can do to repear this?
Thanks.

Set your base_url like below:
$config['base_url'] = 'http://localhost/sistema_clientes/';
Because setting $config['base_url'] = 'sistema_clientes/'; makes sense that
you are going to sistema_clientes controller so base_url
becomeshttp://localhost/sistema_clientes/sistema_clientes.

Related

How to display correct link in CI anchor

I have a form with upload file option.
I get the file_path on $data uploaded by user. Now I want to use this
file_path to be the link in my anchor tag.
My problem is i can't get the correct link. it seems like that the base URL was being included in the link showed in the lower left of the screen.
I also read some post here to add "http://" before the link. but the link appeared was like this
c/xampp/htdocs/.../uploads/products/filename.pdf
no colon.
any idea on how can I access my uploaded file be access via link.
Thanks
paste this line in your /applications/config/config.php just right before
$config['base_url'] = "";
and change this to
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
$root = $protocol.$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
This approach makes your base_url() function returns the current host or url you are in. Even if you upload this to any server it will always return the exact url of your website.
Then you use it like this
<?= base_url('uploads/products/filename.pdf'); ?>
That's all you have to do. Hope this helps!

How to remove index segment in my codeigniter url

I am using rest controller api by phil sturgeon this is the url
paycent/user/index/id/1. Thanks in advance!
you need to set route for that.
set route in your application/config/routes.php file
$route['paycent/user/id/(:any)'] = 'paycent/user/index/id/$1';
Note : If paycent is your project name than remove it from your route. and for creating link you just need to write <?php echo site_url('paycent/user/id/1'); ?>. It will redirect to indexmethod.
In application/config/config.php :
Change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';

Code-igniter href duplicate base url

<li>Home</li>
that give to me localhost/farmex/localhost/farmex/home
and suppose to be localhost/farmex/home
in routes.php you can set $route['default_controller'] = 'home'; and change your code to
<li>Home</li>
Hope this help! ^^
base_url need to set to get proper link from site_url function.
At your application/config.php you need to set
$config['base_url'] = 'http:/localhost/farmex/';
$config['index_page'] = '';
Remember $config['index_page'] is also important.
If you set
$config['index_page'] = 'index.php';
site_url('home') will produce http:/localhost/farmex/index.php/home
$config['index_page'] = 'index.php?'; will produce http:/localhost/farmex/index.php?/home which is needed sometimes.like if you don't want to use .htaccess file.

how to make codeigniter routing to work with paging

I have the following routes for the news that works like a charm:
$word5 = urlencode('mygreek-keyword-here');
$route[$word5] = "news/displayAllNews";
and this page display all news with the desired keyword in the address bar. But...there is always a but...I have paging on this page, so when i click on next page link...page works but with old non-friendly seo url, that is:
news/displayAllNews/10/10
while I would like to have is: mygreek-keyword-here/10/10
code that i have in my controller for the paging is as follow:
$config['base_url'] = site_url('/news/displayAllNews/'.$limit.'/');
what should i do in routes.php and in my controller to get the desired result?
Regards, John
You could get the string of URI by $this->uri->uri_string() method, and set the pagination config as follows:
$config['base_url'] = site_url($this->uri->uri_string() .'/'. $limit.'/');
Note that the URI library is loaded automatically, it doesn't need to load it manually.
Update:
Change the route rule to:
$route["$word5(.*)"] = "news/displayAllNews$1";
If it doesn't work yet, remove the .'/'. $limit.'/' phrase and let the pagination to add the limit itself by:
$config['per_page'] = 10; // or $limit, default items per page.
$config['use_page_numbers'] = FALSE;

Change Codeigniter url

I'm using Codeigniter.I want to set href attr to something like :
<a href="/contact.html" >Contact</a>
But i get 404 error because i should write
Contact.
Where is some thing to fix this problem.
Any help please.
Assuming that you have a controller by the name Contact and you successfully extend the CI_Controller class, go to application/config folder and in config.php find:
$config['base_url'] = 'http://www.youdomain.com/';
Then in your internal links you should do:
Contact
If you are using javascript to make the redirect, put on top of the js file:
var host = 'http://www.yourdomain.com/';
Again:
window.location.href = host + 'contact';
If you're using codeigniter, you do not want to point to an .html file.
If you're using codeigniter correctly, you should use the helper methods that exist in codeigniter.
Instead of writing the anchor tag yourself, try this:
<?php echo anchor('contact', 'Contact'); ?>
to add the suffix to your controller in calling go to config/config.php and search for
$config['url_suffix'] = '';
and assign html to it to become
$config['url_suffix'] = 'html';

Resources