useruser useruser - 18 days ago 6
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:

<?php
echo form_open("controller_admin/method1");
?>
<?php
echo form_close();
?>


but when i wrote this:

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


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.

Answer

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

$this->load->helper('url');

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.

Comments