Form actions |
[eluser]baalwww[/eluser]
YANQ (yet another newbie question)... I have the form action in my form as Code: action="admin/process_login" What I find is that when I submit the form, the function index() in my controller gets executed. I end up back at the login form, via index() calling login() in the controller, with the uri showing being index.php/admin/login and the '***here' in the code below not appearing. This is all fixed if I have the action as Code: <?php echo base_url();?>index.php/admin/process_login Here is the applicable part of my controller Code: function index()
[eluser]Teks[/eluser]
Are you using the Form Helper? With the Form Helper, you can use a function such as form_open() to automatically generate the opening tag - and full action attribute - for you, automatically, without having to worry whether you should include index.php or not. In your view, for instance, instead of the html form opening tag, you would simply use: Code: <?= form_open('admin/process_login') ?> And it would automatically generate: Code: <form method="post" action="http:/yourURLfromCONFIGfile.com/index.php/admin/process_login" /> Optional, extra attributes can be passed as part of the function, too - such as name/id, etc., which make it easier to style the form via css, or enhance it with javascript later. I hope this helps.
[eluser]baalwww[/eluser]
The helper would certainly be a shortcut to creating a full URL link, but having a full URL reference for internal links isn't the best approach in terms of performance. I'd prefer to use relative links. I'm surprised if CodeIgniter actually breaks pages that choose not to use pieces of it, if that's the case.
[eluser]darkbrian[/eluser]
I think the problem with relative URLS is that you have to consider where they are relative from...the view... That's why you would use base_url() or form_open()
[eluser]jwindhorst[/eluser]
[quote author="darkbrian" date="1228134612"]I think the problem with relative URLS is that you have to consider where they are relative from...the view...[/quote] That is true, but it's easy enough to add a "/" to the beginning of your relative path which would make them relative to your doc root. "/admin/process_login" would always be relative to what CI considers the base of your application.
[eluser]baalwww[/eluser]
Sure, but when you move the project from a domain where the document root = "/" (mydomain.com/" to a domain where the document root is two directories up (public_html/mydomain/applications/) you'd have to go in and edit everything.
[eluser]jwindhorst[/eluser]
I'm not sure that is accurate baalwww. The "/" refers to where apache thinks the document_root is. So if you move servers, and the document_root on the new server is public_html/mydomain/applications/ the the initial "/" is relative to that path right? Using a starting "/" in a url, in a web app should always be your document_root. Contrary to baalwww's above post, I think this would make apps more portable instead of less.
[eluser]baalwww[/eluser]
That wasn't what I meant. Sorry. I meant that in the first example, the location of the file with respect to the document root is root. In the second example, since the application root is two directories under the document root, the location of the file with respect to document root is different, although relative to the application it is not.
[eluser]jwindhorst[/eluser]
I'm currently using CodeIgniter to develop a large app. The document_root, according to MAMP is "Sites/trunk/". My "Application directory" is the default CI, so it lives at "Sites/trunk/system/application". Technically speaking that still puts the "app dir" two levels below my doc_root, and yet the starting "/" works like a charm. (CI is automatically fixing my paths with the site_url config var). Does that more accurately describe your situation?
[eluser]baalwww[/eluser]
No. In my case, one is a dedicated server, and the other a shared hosting environment. In both cases, let's say a test and production environment, we're talking about mydomain.com/app as the location of the app...BUT DEDICATED SERVER doc root = / app root = /myapp/ so relative to the root, the location of the app files are /myapp/ SHARED SERVER - domains are in a subdirectory off the doc root doc root = / app root = /mydomain/app/ so relative to the doc root, the location of the app files are /mydomain/app the location of the files relative to the app are the same, relative to the doc root they are not |
Welcome Guest, Not a member yet? Register Sign In |