Welcome Guest, Not a member yet? Register   Sign In
function or plugin that can retrieve asset ?
#1

[eluser]runrun[/eluser]
Hi,

My error messages, email messages and notice messages is increasing quickly, I wonder If i can put all the messages in a file, and use a function or class to retrieve it in controller. As the long last message is making controller hard read thoroughly.
#2

[eluser]TheFuzzy0ne[/eluser]
I'm not sure what you mean. Can you give an example?
#3

[eluser]runrun[/eluser]
Somewhere in file system, we have a file asset.php that contains such thing:
Code:
$email_message['register_success'] = 'Dear user, congratulation, you have successfully created an account please activate your account...feel free to contact us if you have problem. Support team.';
$email_message['activation_confirm'] = 'Dear user, your account is now activated.'
$email_message['account_suspend'] = 'your account has been suspended due to ...'
$email_message['new_promote'] = 'Happy holiday, visit us for plenty of discounts';

Controller:
Code:
$user_email = [email protected];
$message = $this->asset->email_message('register_success');

$this->email->from('[email protected]', 'Yoursite name');
$this->email->to($user_email);
$this->email->subject('Yoursite Account Register');
$this->email->message($message);
$this->email->send();
#4

[eluser]jacobc[/eluser]
You could create email views perhaps... For the body of the messages.

So do

$this->email->message($this->load->view('email/registration',$data,true));

Then you can pass any data and do the body of the message in a view file.
#5

[eluser]TheFuzzy0ne[/eluser]
I'm wonderng if your asset.php may be better off as a language file.
#6

[eluser]runrun[/eluser]
i think you right. That will do.
#7

[eluser]xwero[/eluser]
The problem i have with one time messages like activation_confirm in the above code is that you usually have to store them in a file with unrelated messages. A possible solution is this
Code:
// config.php
$config['default_lang'] = 'english';
// MY_Language.php
function one_line($line,$lang='')
{
   $CI =& get_instance();
   $lang = (strlen($lang)==0) ? config_item('language') : $lang ;
   // if the site content is in the default language no need to load a file
   if($lang == config_item('default_lang'))
   {
      return $line;
   }
  
   $CI->load->helper('url'); // to be safe

   if( ! file_exists(APPPATH.'languages/'.url_title($msg, 'underscore', TRUE).EXT))
   {
      return false;
   }

   ob_start();
   include(APPPATH.'languages/'.url_title($msg, 'underscore', TRUE).EXT);
   $langs = ob_get_clean();

   if( ! isset($langs[$lang]))
   {
      return false;
   }

   return $langs[$lang];
}
//dear_user_your_account_is_now_activated.php (example line file)
<?php
array('dutch'=>'Beste gebruiker uw profiel is nu toegankelijk');  
// usage
$this->email->message($this->one_line('Dear user, your account is now activated.'));
The bad things are that you need to keep the default language line and the line filename synchronized and the filename can be long.

The functionality could be made more like the language class works now but then you have to load the file every time.
Code:
// MY_Language.php
function one_line($line,$lang='')
{
   $CI =& get_instance();
   $lang = (strlen($lang)==0) ? config_item('language') : $lang ;
  
   if( ! file_exists(APPPATH.'languages/'.$line.EXT))
   {
      return false;
   }

   ob_start();
   include(APPPATH.'languages/'.$line.EXT);
   $langs = ob_get_clean();

   if( ! isset($langs[$lang]))
   {
      return false;
   }

   return $langs[$lang];
}
//account_activated.php (example line file)
<?php
array(
    'dutch'=>'Beste gebruiker uw profiel is nu toegankelijk.',
    'english'=>'Dear user, your account is now activated.'
);  
// usage
$this->email->message($this->one_line(account_activated));
the default_lang config setting isn't needed.




Theme © iAndrew 2016 - Forum software by © MyBB