Welcome Guest, Not a member yet? Register   Sign In
Trying to add a theme and it only works for the "home" page.
#1

[eluser]agentkirb[/eluser]
I'm trying to add a theme via bootstrap. So I copy and pasted over the html that was in the theme's index code (as well, as copying over all the files into style/css/js folders in the root project folder). I put it into views/averages/index.php. I'll type in http://localhost/CodeIgniter/ and get a website WITH the theme. But when I tried to do it for http://localhost/CodeIgniter/index.php/averages, I don't get the theme but it still loads the same table. Both websites are effectively the same due to all the routing/htaccess rules. But for some reason accessing it one way allows the theme to work, but the other way the theme doesn't work but the rest of the website loads the same.

Here's the .htaccess file that basically gets rid of the index.php from the address:
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]


Here are my routing rules:

Code:
$route['default_controller'] = 'averages';
$route['averages/create'] = 'averages/create';
$route['averages/(:any)'] = 'averages/view/$1';
$route['averages'] = 'averages';

'Default controller = averages' I'm assuming is what makes it so that when I just type in 'localhost/CodeIgniter' it automatically directs to the averages controller, which loads index, which loads the view, etc.

Anyways, I don't know if it's the routing rules, the .htaccess file, or the views/averages/index.php file (which I've attached named doc.txt) that is causing the problem.

Edit: Also for those curious about the file archetecture:
Controllers
-Averages
-Teams
Views
-Averages
--Index
-Teams
--Index
-Templates
--Header
--Footer

And then stuff like Models, Config, Helpers, etc (and obviously all the bootstrap stuff). I copy/pasted the theme in the header and footer files. Again, it works for the home page, but when I access it directly (index.php/averages) it doesn't work.
#2

[eluser]agentkirb[/eluser]
So just another update: I'm honing in on what could be potential problems.

This is a line of code from the header file:

Code:
<link href="../CodeIgniter/bootstrap/css/bootstrap.css" rel="stylesheet">

Again, when I run this, the theme loads when I goto 'localhost/CodeIgniter' but not when I add 'index.php/averages' to the end of it. And both of those are the same website essentially but just one I made the default controller and used htaccess files to take off index.php and the other is the direct access version of it. And 'index.php/average' isn't the only thing that doesn't work, it seems like anything other than the home page doesn't work.

So what I'm thinking could be potential solutions are:
1. Do a full link path
2. Change routing rules or default controller
3. Something involving the htaccess files. I'll probably have to learn more about them.

If anyone has any other ideas I could try or angles to approach this from, I'm all ears.

Thanks.

Edit: Haha... the first option did the trick. Well don't I feel stupid now.

Edit2: After messing with it more, technically it worked... I got index.php/averages to work, but now regular localhost/CodeIgniter doesn't work and neither does my other files.
#3

[eluser]noideawhattotypehere[/eluser]
I link it like that:
Code:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>bootstrap/css/bootstrap.min.css">

And i never had any problems with diffrent urls.
#4

[eluser]agentkirb[/eluser]
[quote author="noideawhattotypehere" date="1375773126"]I link it like that:
Code:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>bootstrap/css/bootstrap.min.css">

And i never had any problems with diffrent urls.[/quote]

Code:
<link href="<?php echo base_url() ;?>/css/bootstrap.min.css" rel="stylesheet" media="screen">

I do that and nothing shows up. I think you still might be onto something though. The css folder is in the same root folder as the application folder.

Edit: I think the fact that nothing shows up means there was something wrong with how I did echo base_url();
#5

[eluser]noideawhattotypehere[/eluser]
Dont add '/' after base_url(), its already there.
#6

[eluser]agentkirb[/eluser]
I tried both with and without (and with and without the ; in the php code).
#7

[eluser]noideawhattotypehere[/eluser]
Hmm i simply copy/pasted your code into my project changing only part after '?>' and every single page worked with bootstrap. I really have no idea what might be causing it.
#8

[eluser]agentkirb[/eluser]
It has to be the hierarchy or something in config that is different.

$config['base_url'] = 'http://localhost/CodeIgniter/';
$config['index_page'] = '';
$route['default_controller'] = 'averages';
$route['averages/create'] = 'averages/create';
$route['averages/(:any)'] = 'averages/view/$1';
$route['averages'] = 'averages';

Maybe I just need to delete the last 3 routes because they don't really do anything that I'm aware of. Or change the folder hierarchy.
#9

[eluser]agentkirb[/eluser]
I tried to echo base URL to make sure it was what I thought it was.
echo base_url(); in my averages controller

Call to undefined function base_url() in C:\xampp\htdocs\CodeIgniter\application\controllers\averages.php on line 18

So it's base URL itself.
#10

[eluser]agentkirb[/eluser]
Ok, did some googling and I needed this:

$this->load->helper('url');

I still haven't fixed the problem but base url works

Edit: Ok, putting this line of code in all the controllers seems to have fixed it.




Theme © iAndrew 2016 - Forum software by © MyBB