Welcome Guest, Not a member yet? Register   Sign In
form_open & mod_rewrite
#1

[eluser]MikhailFerreira[/eluser]
With the Form Helper from CodeIgniter - form_open - I have specified something similar to...
Code:
echo form_open('news/create');
...to begin the a form and I am using mod_rewrite with .htaccess to remove "index.php" from the URL.

The problem that I am coming across is that the action attribute in the form's opening tag, is being compiled with "index.php" like so:
Code:
http://www.website.com/index.php/news/create
...instead of what I would like it to do:
Code:
http://www.website.com/news/create
At the moment I am using "str_replace" to remove "index.php/" from the opening tag...
Code:
echo str_replace('index.php/','',form_open('news/create'));
...but this is not ideal, because it almost defeats the purpose of the simplicity of using this helper in the first place.

Are there any other solutions that relate to this helper?
Could it be somewhere in the documentation I might have missed?
#2

[eluser]MikhailFerreira[/eluser]
I have found a solution after a bit of fiddling - simply change:
Code:
$config['index_page'] = 'index.php';
to:
Code:
$config['index_page'] = '';
I'm not sure if this is a sure-fire solution - due to my lack of experience with CodeIgniter - that won't implicate future problems, but it works for now...
#3

[eluser]PhilTem[/eluser]
This is THE solution to your problem since form_open will always include the index_page config item. If you don't want this, just set it to an empty string. But don't forget using an .htaccess to make your app work again Wink
#4

[eluser]MikhailFerreira[/eluser]
Thank you for the reply and additional info, PhilTem.
Yes yes, using .htaccess to accomplish mod_rewrite. Smile
I noticed that it affects some other helpers that use the same principle too.
#5

[eluser]Aken[/eluser]
form_open() uses the site_url() URL helper function, which is also used in other various places. Always check the source code if you're unsure.
#6

[eluser]MikhailFerreira[/eluser]
Found another solution:
Code:
echo form_open($this->uri->uri_string());
If you would not want to remove the:
Code:
$config['index_page'] = 'index.php';
#7

[eluser]MikhailFerreira[/eluser]
Or simply:
Code:
echo form_open(uri_string());




Theme © iAndrew 2016 - Forum software by © MyBB