Problem using anchor tag (solved) |
[eluser]bananamuffin[/eluser]
[quote author="jedd" date="1256601961"]Wow - top-posting in forums - that's a new one. You don't have to quote messages unless there's something specific you're responding to. [/quote] What do you mean by this? I quoted InsiteFX because the first line in my post was a reply to his advice. [quote author="jedd" date="1256601961"] Unless http://localhost/CI/posts resolves on your computer, it's not an anchor issue but a controller/method or pathing issue. Does that URL resolve normally? [/quote] What do you mean by resolve normally? When I click on the link I've created with the anchor tag I get that url in my address bar but the page loads with a HTTP 404 Page Not Found error. [quote author="jedd" date="1256601961"] Remember - page/view-source within your browser is your friend with this kind of problem.[/quote] View source does not reveal anything in this case, just the Page Not Found error.
[eluser]bananamuffin[/eluser]
OK, so I was able to get version 2 of the site working fine (in CI v1.7.1). The css in the posts page showed up after I added <base href="<?php echo base_url(); ?>"> in the <head> of my template, following the recommendation from http://philsturgeon.co.uk/news/2009/09/A...e-BASE-tag But how do I get my links to work with htacess and index.php removed from config.php? Going to keep working on it, hopefully I'll figure it out or get an answer.
[eluser]cahva[/eluser]
In rare cases you actully have to use base href so leave it out, you dont need it. Ok. You have just copied Codeigniter files on your localhost directory called CI. So you will set $config['base_url'] like this: Code: $config['base_url'] = 'http://localhost/CI/'; Ok.. To get rid of index.php with .htaccess first set $config['index_page'] to '' in the same config.php Code: $config['index_page'] = ''; Then .htaccess file in CI/ dir: Code: RewriteEngine on In that file theres the RewriteCond which contains files/folders that will NOT be directed to index.php. I have assets folder where I put my css, js, images etc. which I dont want to go through index.php. You can add your own folder(s) which you use (eg. css, images, js ..). With this setup, if you use: Code: echo anchor('welcome/test','This is a test method in welcome controller'); Code: <a href="/CI/welcome/test">This is a test method in welcome controller</a> Code: <a href="http://localhost/CI/welcome/test">This is a test method in welcome controller</a> Hope you get it now. I dont know how much simpler this could be explained ![]()
[eluser]bananamuffin[/eluser]
Thanks for the detailed explanation. The thing is that I did all this exactly following a tutorial I'm working through. I compared how you've laid it out with mine and it looks the same but I still get the page not found error when trying to load the posts page from the link I constructed with the anchor tag. That's why I'm getting frustrated. Bah! Off to bed, will be back to wrestle with this tomorrow.
[eluser]stormlead[/eluser]
hey guys ! i dont know whats got on the discussion when i left. BUT my problem is still persisting. i am still able to link the page. i am trying as below now Code: echo anchor('system/application/controllers/next.php','Click here'); and getting the error when i click on click here link Fatal error: Class 'Controller' not found in C:\wamp\www\CodeIgniter_1.7.2\system\application\controllers\next.php on line 3 the code for next.php obviously a controller is Code: <?php
[eluser]cahva[/eluser]
It has been said before but dont use the full path to the next.php. Just: Code: echo anchor('next','Click here'); That will give you link like this: Code: // if you have index.php set
[eluser]stormlead[/eluser]
@cahva Thanks for the reply my problem is solved. i jus added the code Code: echo anchor('/next','Click here'); Code: $config['index_page'] = ""; to again Code: $config['index_page'] = "index.php"; ![]()
[eluser]bananamuffin[/eluser]
Any more ideas how to make this work without index.php? I have rebuilt my site from scratch (with v.1.7.2) and this time I left index.php in the config file and didn't create a htaccess file. It works fine except that I have to add Code: <base href="<?php echo base_url(); ?>"> in the head section of my template to make all my assets show. But as soon as I create my htaccess file and remove the index.php from the config, my links to other pages all break. I haven't been able to crack it yet. Any ideas? I have reworked this several times and made sure my setup and code are correct and match the examples given in the user guide, on this thread, and in the tutorial I'm following. I am developing on my localhost using Wampserver v.2 thanks
[eluser]Broussai[/eluser]
Hi, same problem here. My site is in a subfolder named "V1". The .htaccess has been conf to return the url without index.php All works fine except when i try to link to a controller : In views/V1/container_view.php : Code: <?php echo anchor('article',$row->titre_art);?> Code: <?php Error 404 when i try to click on the link (wich link to http://localhost/CodeIgniter_1.7.2/article ) |
Welcome Guest, Not a member yet? Register Sign In |