1

I need to translate value thats why I wrote a function and I need to pass angular value into that php function.

such as php function is

 <?php bn_translate(); ?>

and angular js value is

 {{ result.min_tenure }}

I tried this two ways but nothing changed

<?php print bn_translate("{{ result.min_tenure }}"); ?>
and
{{ <?php print bn_translate("result.min_tenure") }}; ?>

or If I tried for test value that was successful translate

<?php print bn_translate("5"); ?> or <?php print bn_translate(5); ?>

Is it possible to pass value into php function to work properly?

3

3 Answers 3

0

PHP runs first, then angular js. As such your trying to pass a variable from the future (angular js) to a function that was called in the past (PHP).

You are essentially asking PHP to do the following:

<?php bn_translate("null"); ?>

The value in angular JS doesn't exist yet.

The only way to do what you want to do is send the variable via AJAX to a php script with the function.

Sign up to request clarification or add additional context in comments.

Comments

0

You would use an ajax call to pass values from frontend to backend, normally using a format like json. However, for something like translations you should try to avoid the roundtrip to your server, if possible. Good solutions would be using angular-gettext or angular-translate.

controller with injected $http

$http({
    url: "script.php",
    method: "POST",
    data: {
        data: result.min_tenure
    }
}).success(function(translated) {
    console.log(translated);
});

script.php

<?php
$request = json_decode( $_POST['data'] );
$text = $request->data
$translated = bn_translate($text)
echo (json_encode($text));

Comments

-1

You can assign value to the PHP variable and pass to php function

<?php
    $value = "{{ result.min_tenure }}";
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.