URL Flood! |
[eluser]jordanarseno[/eluser]
Hello everyone, I'm having an issue with CodeIgniter..I'll do my best to describe what is happening - I hope someone can help me out. I'm working on a site similar to textsfromlastnight.com. I am pulling information from a database and I have used thumbs-up and thumbs-down icons throughout the page to mark the post as good or bad. Essentially, there is a "good" and "bad" column in my 'texts' mysql table that acts as a counter. First off: Database Options: I will not list - I am certain the database connection is working. Configuration Options: Code: $autoload['libraries'] = array('database', 'parser'); Routing: Code: $route['default_controller'] = "main"; So here's the issue: When I visit http://localhost/CITFLN/index.php/ - I am presented with a list of 'textfromlastnight' entries. When I hover over a thumbs-up icon the bottom of my browser points to "main/good/1" - which is great because "main" is my default controller and "good" is method inside of the class, which accepts an id... The view that calls it is attached as a screenshot at the bottom... (CodeIgniter Forums would not format it properly, so I couldn't post it inline) The controller function is : Code: function good($id) The model function, increment_good in texts_model is: Code: function increment_good($id) As mentioned above, my URL bar says: http://localhost/CITFLN/index.php/ ... And after I click the thumbs up icon, the number in the database increments. So far so good! However, CodeIgniter contaminates my URL bar with http://localhost/CITFLN/index.php/main/good/1 immediately after the click, even though I've asked it to redirect to $this->index(): Code: function index() This is not good, because any subsequent clicks of the thumbs up button don't work because CodeIgniter tries to go to: http://localhost/CITFLN/index.php/main/good/main/good/1 ... which doesn't exist. Hope I've explained well enough. Looking for your suggestions. I <3 CodeIgniter - Thanks to all who've developed - and all of you who are active on the forums. You're a great group of people. Cheers, JoAr
[eluser]CroNiX[/eluser]
try making your links start with / like Code: <ay href="/main/good/$row->id"> If it doesn't start with / it will append it to the current url because its relative. or use the anchor function which does that for you. Code: anchor('main/good/' . $row->id, '<img src="' . base_url() . 'images/good.png" />');
[eluser]jordanarseno[/eluser]
Thank you for your assistance CroNiX! I implemented your first solution... when I click a thumbs up, my URL turns into: http://localhost/CITFLN/index.php/main/good/2 And any subsequent clicks do not pile up in the URL - THANKS! Is there a way I can remove the /main/good/2 though? With the current state, a simple page refresh triggers the good() function and increases the counter. This is undesirable - I'd like to direct the user back to http://localhost/CITFLN/index.php/main/ only. BTW, the code I used in the view: I could not get it working without index.php explicitly stated, and it heavily relies on the existence of this. I actually want to remove this - do you (or does anybody) know how to remove index.php in the URL? I was reading online earlier how to do this - some sort of modrewrite in a .htaccess file? I'm running LAMPP on Ubuntu - anyone know where to find the .htaccess file? - I searched earlier - could not find! Cheers all & Thanks! JoAr
[eluser]techgnome[/eluser]
Try using the redirect function and send it back to your Base_Url. -tg
[eluser]jordanarseno[/eluser]
THANK YOU IT WORKS! Cute dog I'll search a little further for the Linux question. If I cannot find results, I'll start a new thread with a more appropriate title. Again, Thanks guys - much appreciated! Cheers! JoAr
[eluser]techgnome[/eluser]
Regarding the .htaccess file... that's something you would create and put in the root folder of the site. If you haven't expicitly created one... odds are it doesn't exist. -tg |
Welcome Guest, Not a member yet? Register Sign In |