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

[eluser]jrad[/eluser]
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
Code:
<?php
if($mydata == ''){
echo '<p>Empty Table.</p>'; // Print if no data in table.
}elseif($mydata != ''){
echo '<p></p>'; // Print if data is available.
}
?&gt;

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
#2

[eluser]dcunited08[/eluser]
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:
Code:
$this->load->vars(array('obj' => $this));
And then call it using
Code:
$obj->controller_function($data);
#3

[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.
#4

[eluser]JoostV[/eluser]
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.
Code:
if(!isset($mydata)){
    echo '<p>Empty Table.</p>'; // Print if no data in table.
}
else{
    echo '<p></p>'; // Print if data is available.
}
That should do the trick.




Theme © iAndrew 2016 - Forum software by © MyBB