Welcome Guest, Not a member yet? Register   Sign In
Call a controller function from view

Need a little help on this.

I've got a view that displays a login form and two tables which data are fetched from db.

I've been testing form_validation and whenever I try to submit an empty form and get a validation error (which I expect) I also run into problems with the two tables. Because it throws an error everytime the page reloads after an error in the login form is found.

here's the code
if($mydata == ''){
echo '<p>Empty Table.</p>'; // Print if no data in table.
}elseif($mydata != ''){
echo '<p></p>'; // Print if data is available.

Is there a way to call a controller function from within a view file so everytime a view file is reload (for whatever reason) the table will also be reloaded?

Any suggestion or idea will be most appreciated.

PHP error: undefined variable: mydata

Take a look at Wick or Modular_Extensions_-_HMVC. You may also be able to pass an instance of the object to the view using:
$this->load->vars(array('obj' => $this));
And then call it using

[eluser]Pascal Kriete[/eluser]
This sounds like a very straightforward situation, so I would assume that there's a logic error in the controller somewhere. The same data should be available regardless of the form's status.

From the look of it, your view complains that $mydata is not set. Try checking if $mydata is set, instead of checking whether $mydata is an empty string.
    echo '<p>Empty Table.</p>'; // Print if no data in table.
    echo '<p></p>'; // Print if data is available.
That should do the trick.

Theme © iAndrew 2016 - Forum software by © MyBB