view raw
useruser useruser - 6 months ago 38
PHP Question

codeigniter form action tag vs php-html form action tag

I am a beginner in CodeIgniter framework and I have problem with form action.
I don't have any problems when I do it on this way:

echo form_open("controller_admin/method1");
echo form_close();

but when i wrote this:

<form name="form" method="post" action="<?php site_url('controller_admin/method1') ?>">

Form doesn't want to call controller's method method1, and I don't see why?

Because I'm a beginner I would like to know both ways, but currently only the first one is working.


In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php

$autoload['helper'] = array('url');

Or, manually:load it in function construct of controller


Once it's loaded, be sure to keep in mind that base_url() doesn't implicitly print or echo out anything, rather it returns the value to be printed:

echo base_url();

Remember also that the value returned is the site's base url as provided in the config file.