Welcome Guest, Not a member yet? Register   Sign In
Placeholders in language lines
#1

How to use placeholders in 
$this->lang->line('misc_key', FALSE);

It is used in standard libraries  (e.g. from validation), but how to use it in my own libs and models?

Code:
echo sprintf($this->lang->line('somekey'),'XYZ');//load language library before use
Is this the best way?
Reply
#2

(This post was last modified: 06-10-2018, 05:01 AM by InsiteFX.)

Maybe this will help, you can use it in any library Class.


PHP Code:
// Your lang file - Created under language folder language-name
<<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$lang['your key'] = "Your Message.";

// End of lang file


// Your Class
class Your_Class
{
 
   /**
     * @var  CI_Controller - The CI Super Object
     */
 
   protected $CI;

 
   /**
     * constructor.
     * -------------------------------------------------------------------
     *
     */
 
   public function __construct()
 
   {
 
       $this->CI =& get_instance();

 
       $this->CI->lang->load('your lang file''english');
 
   }

 
   /**
     * Your Method.
     * -------------------------------------------------------------------
     *
     */
 
   public function test()
 
   {
 
       show_error($this->CI->lang->line('your message'));
 
       
        
// or

 
       echo $this->CI->lang->line('your message');
 
   }


 
When working outside of a controller you need to get the CodeIgniter Super Object.

Also SEE: The CodeIgniter Documentation on Language files etc;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB