Codeigniter view loads into one view but not another
I have sidebar.php in my views folder. It contains this code:
<div class="title_box">
Login
</div>
<div class="border_box">
<div style="height:150px">
<br/>
<?php echo form_open('login'); ?>
<strong>Username:</strong> <input type="text" name="username" size="13"/><br/>
<strong>Password:</strong> <input type="password" name="password" size="13"/><br/>
<div class="login_button">
<p><input type="image" src="/igniter/assets/images/login.gif" name="login"></p>
</div>
</form>
<div class="forgot_name">
<br/>
<a href="">Forgot username or password?</a>
</div>
</div>
</div>
I have two other views. index.php and registration.php.
In registration.php, in the appropriate point, I do:
$this->load->view('sidebar')
It loads my sidebar exactly as expected in my registration page.
But the same code, in index.php vi开发者_运维知识库ew, gives me an error and refuses to show the sidebar.
This is the error I get:
You need to load the form helper, or the form_validation library (which automatically includes the form and url helper) in the controller calling those views (or one of them, as views are buffered so you can call one inside another and have the same vars available).
The error means the function form_open(), which is inside the form helper, is not being loaded.
Thnaks to @Robin Castlin for the example code. In your controller, load
$this->load->helper('form');
OR just
$this->load->library('form_validation');
The you can load your views.
精彩评论