Hi,
I've read other questions and replies about this error but I'm not able to find the right solution to me.
in actions>load I've added a PHP module with this function:
Thanks in advance for any help.
I've read other questions and replies about this error but I'm not able to find the right solution to me.
in actions>load I've added a PHP module with this function:
function test($field) {in my view I call it like:
if ($this->data("language")=="it-IT") {
echo $this->get("read_data1.db_test_it.', $field,'_it");}
else {
echo $this->get("read_data1.db_test_en.', $field,'_en");}
}
test("MyField");The idea was to read and print the field "read_data1.db_test_it.MyField_it" if the interface is in Italian and "read_data1.db_test_en.MyField_en" in any other case but when I load my form I have the error "0 USING $THIS WHEN NOT IN OBJECT CONTEXT" and I really can figure out what do I have to do to have it working.
Thanks in advance for any help.
using $this should be fine, but your code has a quotes problem, please try to fix this first ?
Thanks for reply Max, you are right, I made some mess with quotes but I tried this just to take it easy
function test() {then I call it like
$text = $this->get("read_data1.db_test_it.ID");
echo $text;
}
test();and the same errore appear, If I write
<?phpin views it works, what am I missing?
$text = $this->get("read_data1.db_test_it.ID");
echo $text;
?>
what if you test the 2 lines of code without the PHP tags ?
If I add a PHP module in actions>load with those two lines (so not creating a function) I have no error but no data too, I also add some text to the echo like
echo $text,'abc';and then I see abc and nothing more, if I copy the same code in a html module in views (with PHP tags) ID field is correctly displayed.
I added a PHP action to the first page and used this code:
function test(){that showed 123 on the top of the form which is the expected behavior!
echo 123;
}
test();
Sorry for my English Max, I couldn't explain what I did.
In Actions>load>PHP module I wrote
Thanks again for the support.
In Actions>load>PHP module I wrote
function test() {Then in Views>HTML module I wrote
$text = $this->get("read_data1.db_test_it.ID");
echo $text,'abc';
}
<?phpThe result when I load the form is
test();
echo '<br>';
$text = $this->get("read_data1.db_test_it.ID");
echo $text,'abc';
?>
abcSo ID wasn't read in the function but only in the view code, no error reported.
25abc
Thanks again for the support.
the PHP is above or below the "read_data1" ?
You are right, it was before read_data1, now I moved it below but I got again the "0 USING $THIS WHEN NOT IN OBJECT CONTEXT" error when loading the form.
well, it looks like $this will not work inside a function defined in the PHP code, you will need to make the function take $this as a parameter (do not name it $this), and pass $this in the function call!
No problem!
You need to login to be able to post a reply.