(02-24-2016, 03:52 PM)acheng16 Wrote: So I have a view called select_dates.php and it takes in POST data (start date, end date, and product ID). Once you press submit
$this->load->private_view('reports/edit', $data);
which will load a view that has the report based on the POST data given. However this view(reports/edit) also has a form at the top which can ask for these same 3 POST data in select_dates.php. However once I press submit here the data isn't getting posted at all. Any thoughts or ideas?
Where is select_dates.php and where is it called from? The code you included doesn't have it.
Also, now that I notice, what is $this->load->private_view? Is private_view an extension of the loader library? Could it be that it has the error where data passed to a view is not available in all views? Check out this simple example.
controller home.php
PHP Code:
public function index()
{
$user_id = $this->session->userdata('user_id');
$data = array (
'user_login' => $this->session->userdata('user_login'),
'menu' => array (
'Lists' => 'glist',
'Memberships' => 'glist/membership',
'Wish List' => 'gifts/wishlist',
'Gifts' => 'gifts/commitlist',
'Logout' => 'user/logout'
)
);
$this->load->view('home_view', $data);
}
}
view home_view.php
PHP Code:
<?php $this->load->view('header'); ?>
<div id="content">
<!-- content goes here -->
</div><!-- content -->
<?php $this->load->view('footer'); ?>
view footer.php
PHP Code:
<div id="sidebar">
<?php if ($this->session->userdata('user_id')) : ?>
<h2>User</h2>
<p><?php echo $this->session->userdata('user_login') ?></p>
<?php endif; ?>
<dt>
<?php foreach ($menu as $name => $link) : ?>
<dl><a href="<?php echo $link ?>"><?php echo $name ?></a></dl>
<?php endforeach; ?>
</dt>
</div><!-- sidebar -->
</div><!-- page -->
</body>
</html>
In the home controller, I load the user id and the menu into
$data and then I go
$this->load->view('home_view', $data);
So far, so good. The view home_view receives
$data and converts its elements into variable. Then the view home_view calls the view footer.php. Note that it does not send it any data. It won't need to. When CI loads the view footer.php, the variables extracted from the
$data are already available without having to do anything.
I could also have called all views from the controller instead of the controller calling one view that then calls other views. It works the same either way. So I'm suspecting private_view.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!