Installing CI in a subdirectory |
[eluser]nvhack[/eluser]
Sorry to repost this one again but I haven't found any answers by searching the forum. It seems that I should be able to install CI in a sub directory. But when I do linkage to images files get weird when there is no trailing slash / This was described more throughly here. http://ellislab.com/forums/viewthread/90756/ The thing I find most confusing is that the HTML paths in the source do not change?? I am not using any htaccess files and I have not touch the routing settings.
[eluser]Mirage[/eluser]
You would probably get a lot more help if you concisely laid out your folder structure, showed us your config and an url string that causes problems. 1. You don't need to put CI into the sub-directory per se. All you really need is to put an index.php in the subdirectory and setup the system and application paths correctly. 2. Your resources (images, css, js) aren't handled by CI and therefore should work just like they would if you used regular html files. HTH, -m
[eluser]nvhack[/eluser]
I will try what you suggested and put the index.php in the subdirectory. IN the meantime, Here is my file structure. Here is my structure: htdocs/ci/ htdocs/ci/images/tpl/ htdocs/ci/system/application/views/ My config is set to $config[’base_url’] = “http://localhost/ci/”; This is running on XAMPP - no .htaccess files I constructed a simple header view the with a css link and a image link. and load that view immediately before the view for the content like so $data['page_title'] = 'Test page'; $data['page_header'] = 'Page title'; $this->load->view('header', $data); $this->load->view('content', $data); Here’s whats happening. If I view the page like this with the trailing slash all is groovey http://localhost/CI/index.php/admin/ If I view the page without the trailing slash like this http://localhost/CI/index.php/admin the view loads but does not load the CSS or the image. A look at the browser source shows that the paths to the css and image are identical. This occurs in Firefox and IE and in other views.
[eluser]metaltapimenye[/eluser]
Code: function something(){ and make "$this->load->view(’header’, $data);"-part overwriten. Code: function something(){
[eluser]Michael Wales[/eluser]
Use an absolute reference on your images and css Code: <img src="<?php echo base_url(); ?>images/tpl/header.png" />
[eluser]nvhack[/eluser]
Thank you, I am loading my views inside a function Yes, adding the base_url() fixes my issues. Specifically, when I add the trailing slash the image displays. but it seems to me that I should not have to do that... Without the base_url() added the image would not display with a trailing slash. And again this is really odd behavior because a peek at the rendered source shows the correct path in each instance. I am going to try and put this on another web server and see what happens.
[eluser]Michael Wales[/eluser]
I believe this depends on how your webserver is configured and mod_rewrite can handle most of these issues. Personally, I find the absolute path much easier to manage. But - let's say your image code is this: Code: <img src="./assets/images/header.png" /> Now - my URL is http://example.com/ so the browser goes looking for this image: http://example.com/assets/images/header.png Now - your user clicks your login link, which sends them to the controller/method user/login. Our URL is now http://example.com/user/login so the browser is looking for this image: http://example.com/users/assets/images/header.png Unless of course you are using mod_rewrite to ensure that there is a trailing / on each of your requests. So the URL then becomes http://example.com/user/login/ and the image looked for is http://example.com/user/login/assets/images/header.png. Such a PITA, IMO. The only simple way I can think of is to reference your images in relation to root: Code: <img src="/assets/images/header.png" /> For me - that simply wouldn't work because I would have to reference that particular projects subfolder off of my webroot. Then when it comes time to deploy, I would have to manually change all of that xHTML. I'd much rather use base_url() and let the framework figure it out for me - never have to change a thing except the config.php...
[eluser]Mirage[/eluser]
What Michael suggest is true. Using absolute paths keeps you mostly out of trouble. Still - it's possible that you don't want to share the site's resource pool and keep your application 'movable'. In such case, you can use the html 'base' tag in your templates. Simply echo your base_url config setting in there and now it will work by using relative links in the template AND using url helpers, etc. Code: <base href="<?= $this->config->item('base_url')?>"/> and use Code: <img src="img/logo.gif"/> In your templates. Cheers, -m
[eluser]nvhack[/eluser]
Thanks! Its going to take a while for me to process all this but I think this gets to the root of it.
[eluser]zorka[/eluser]
Get's to the "root" of it... I like that... I am seeing the same type of issue with a site I am working on. It is usually hosted on a traditional root (\) directory but while I have it, I put it as a subdir in my IIS Root folder (c:\inetpub\wwwroot\myfile\)... I'm having similar issues with referencing resources (imgs and css files) as well as forms that post to controllers. Did you figure a way to do this without having to add baseURL function/variable to every place you reference anything? (seems like a royal pain to me!) |
Welcome Guest, Not a member yet? Register Sign In |