MixedCoder MixedCoder - 7 months ago 15
PHP Question

Codeigniter use lang->line in a helper

what am trying to do , is using

language helper
inside diff helper

$this->CI =& get_instance();


if (!function_exists('execute_dynamic_constants')) {
function execute_dynamic_constants()
{
?>
<script type="text/javascript">
var promptMsg = '<?php $this->CI->lang->line('success');?>';
</script>
<?php

}
}


but it seems that the
language helper
is not being loaded, when am loading it inside the
$autoload['helper'] = array('url', 'file', 'language', 'form', 'Functions','DynamicJs');


what am missing here?

Answer

It looks like you are missing an echo to print the line to the HTML.

var promptMsg = '<?php echo $this->CI->lang->line('success');?>';

Also, CI 2 docs state that $CI->lang->line() is deprecated in favor of lang(); https://ellislab.com/codeigniter/user-guide/libraries/language.html

This is how I made your example work:

if (!function_exists('execute_dynamic_constants')) {
    function execute_dynamic_constants()
    {
        ?>
        <script type="text/javascript">
            var promptMsg = '<?php echo lang('success');?>';
        </script>
        <?php

    }
}

I dropped the $CI reference, since it is no longer needed if the lang(); from the preloaded language helper is used. Hope it helps :)

Comments