Bootstrap glyphicons behaving strange in codeigniter - php

So I'm using CI for the first time, along with bootstrap. Weird thing is happening with the glyphicons on my pages.
If I start my url in the browser with "www.", it all works fine. If I don't use it (so example.com instead of www.example.com), the glyphicons do not show. In their place are empty square boxes.
Can someone explain to me why it is behaving like this?
$config['base_url'] = 'http://www.[mysitehere].ovh/';
Note: If I change the above to 'http://[mysitehere].ovh' then the reverse is true. If the www. at the beginning is present, then the glyphicons don't work and vice versa.

I dont see how is that related to icons, but better solution is to add in config.php
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'];

Try with:
$config['base_url'] = '';
CodeIgniter is able to figure out the base URL by itself.

Related

CodeIgniter URI routing with "#" as path parameter [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 2 years ago.
I have a Home.php controller and terms method in it. I have a url like this: https://www.example.com/terms and it works fine.
My routes.php:
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['terms'] = 'home/terms';
Now, I need to change the url to be like this: https://www.example.com/#/terms Notice the "#" in-between.
I tried adding this to routes but it didn't work:
$route['#/terms'] = 'home/terms';
The above change show home page when I open https://www.example.com/#/terms
However, if I put any other permitted character $config['permitted_uri_chars'] mentioned in conifg.php in place of # then it works fine:
$route['a/terms'] = 'home/terms'; // this works: https://www.example.com/a/terms
$route['2/terms'] = 'home/terms'; //this works: https://www.example.com/2/terms
I also added # in $config['permitted_uri_chars'] but that too didn't work. Keeps showing home page only.
Also, can anyone explain me why # is not treated the same way as other characters in permitted_uri_chars?
Controller is Home.php and method is terms(). Using CodeIgniter version 3.1.11
Thank You!
EDIT:
I need to know if I can achieve it using Codeigniter's routing? Or maybe some rewrite rule using .htaccess?
This is caused by the web browser, not CodeIgniter. Web browsers treat # and anything after it in a URL to be a reference to an element on the web page pointed by the URL before the # part.
So for a URL https://example.com/#page1, the web browser will make a request to https://example.com/ and then look for an element with ID page1 on the web page.
If you want different pages to load by using a '#' in your URLs, it's done using front-end frameworks like Angular. Check Angular's routing features to understand how it makes the browser load a different view for different URI paths after #.

Integrating Codeigniter and Wordpress

I designed a site using Wordpress, and have been trying to get a Codeigniter form app integrated with it, with all the corresponding URLs.
I put the CI app in the root folder of the Wordpress site. The folder is named "Chile" (it's a series of forms separated by LATAM countries). I changed the .htaccess file to include /chile where necessary. I also added:
require '../wp-load.php';
to the CI index.php file.
I can now load some of the essential urls in the CI app, but they don't seem to be routed properly.
the base url is set to:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('#/+$#', '', dirname($_SERVER['SCRIPT_NAME'])).'/';
the site is www.dermusikplatz.com. the form is located under www.dermusikplatz.com/chile/applications which i can reach by manually entering that. but when i try to submit the form, the url appears strangely as www.dermusikplatz.comapplications/save. In general, the urls constructed by the controllers and views just don't seem to be set up properly.
I've looked up the documentation regarding routing and have tried creating a $route rule. but i'm not sure what to route from and to what exactly. I've also seen various threads that suggest using MY_URL_helper to change the value of 'site_url' to 'ci_site_url', to avoid any redundancies between the value that Wordpress and CI have for that, but i'm not sure where to even start with that, even after checking out the helper documentation.
I've also tried going in and changing each path value in statements like these from:
$this->load->view('applications/form');
to:
$this->load->view('/chile/applications/form');
but I understand that makes little sense as that directory doesn't exist. I assumed that changing the .htaccess file and the base_url would cover it, but there seems to be much more to it than that.
I'm a little lost here, and not super familiar with Codeigniter.
If anyone can help set me in the right direction at the very least, I would really appreciate it. Thanks.
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
Change that to:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'] . '/Chile/';
It is worth noting that if you are hosting on Linux the 'Chile' must be the exact same case as your folder is called. So, if it is 'Chile', do not call it 'chile'

not getting proper base_url in codeigniter app

i am getting this type of url when trying to access pages other than index page
http://localhost:8012/health-care/8012//localhost/health-care/index.php/index.php/home
but url to access page must be
http://localhost:8012/health-care/index.php/home
my problem in url is: "it is duplicating url after "i hhttp://localhost:8012/healthcare/ that should not be duplicated.
i have autoloaded url helper in autoload.php as well as manually in constructor of controller. my base_url in conf
$config['base_url'] = 'http//localhost:8012/health-care/index.php/';
Guide me about this problem.
in addition to tell you that i have two app fron one codeigniter i.e. frontend and backend.
Url for backend works properly but for frontend its giving me mistakes what to do ?
$config['base_url'] = 'http//localhost:8012/health-care/';
used this base url you getting this url
http://localhost:8012/health-care/index.php/home
Y0u have to change this line
http://localhost:8012/health-care/index.php/home
to this
$config['base_url'] = 'http//localhost:8012/health-care/';
Please have a try.
Try this code:
$config['base_url'] = 'http://localhost:8012/health-care/';
and also make index_page as empty like this:
$config['index_page'] = '';
.htaccess file was not working. just replaced file and my problem got solved.

Codeigniter, bypassing the main or default controller

i tried to find solution, but i think i am quite doing something wrong here,
i hope any one with good knowledge of codeigniter routing can help me in this regard.
what i want is that,
i have default controller named main
$route['default_controller'] = "main";
$route['404_override'] = '';
my site urls are like
mydomain.com/main/#home
mydomain.com/main/#search
mydomain.com/main/#login
what i want is to remove/hide the main from center and links can directly work.
like this
mydomain.com/#home
however i did succeeded a little using codeigniter documentation.
This is what i did to achieve it.
in route file i added this
$route['(:any)'] = "main/$1";
it worked but it messed up with other links.
First now domain.com/main/#home stopped working.
second, now i cant have other controller name here??
i mean if i try this domain.com/virtualvault/#search, it wont work..
What i am trying to have that,
When i go to domain.com/main/#home it should go to home page
and also when i try domain.com/#home it should also go to same home page
not to forget that i want other controllers to be working fully.
i mean, domain.com/othercontrollername/#function should work.
what and how to achieve it, .htaccess or route php file..
i even tried this below route code.
$route['#+(:any)'] = "main/#+$1";
but i am no good in this routing or .htaccess files.
any ideas how to achieve it??
// The below line is for the old controller to work as before
$route['main/(:any)'] = "main/$1";
//This line is for making other controllers work as before, you have to put them all
$route['virtualvault/(:any)'] = "virtualvault/$1";
//This is the last line; the order is important
$route['(:any)'] = "main/$1";
If you need only those three URLs (home, search and login) to work without the controller name, just put the three of them in routes.php ($route['login'] = "main/login";, etc.) and use no wildcards in order to prevent other URLs from getting rerouted.
So, all of them should be:
$route['home'] = "main/home";
$route['search'] = "main/search";
$route['login'] = "main/login";

Creating short url for multiple controller?

For my current project in codeignitor I needed to make user profile like this
http://domain.com/userid
Then I tried to add this in router.php
$route['(:any)'] = 'profile/user/$1';
Which is working fine. Now I want to make another URL for language like this
http://domain.com/es
http://domain.com/fr
As for both url uri segments are first, when I type
http://domain.com/es
I see the page of
http://domain.com/userid
I am using .htaccess file for removing index.php in codeignitor. Is there any help how can I achive this task in making shot url for multiple controller. Either with .htaccess or router.php?
Because the routes system works from the top down, if you have multiple rules that can match a url, it picks the first one. So you could do:
$route['(es|fr|en)'] = 'language/$1';
$route['(:any)'] = 'profile/user/$1';
If the first rule matches, it runs, otherwise it tests the profile rule.
You will definitely continue running into issues though with that profile rule, and it would be easier if you did something like:
$route['users/(:any)'] = 'profile/user/$1';
That way it would be more clear what the url is doing, and it will help you for when you are writing rules in the future.

Categories