खोज…


पुस्तकालयों और सहायकों का उपयोग करना

उदाहरण पुस्तकालयों और सहायकों के उपयोग के उदाहरण के उद्देश्य के लिए है न कि एक वैध कोड के लिए। इसे अपनी परियोजनाओं पर कॉपी / पेस्ट न करें।

हेल्पर्स हेल्पर्स / sendEmail_helper.php

if ( ! function_exists('sendEmail'))
{
    function sendEmail($email, $subject, $message, $lang, $cc = null, $file = null) {

        $CI =& get_instance();    
        
        $mail_config['protocol'] = 'smtp';
        $mail_config['smtp_host'] = 'host';
        $mail_config['smtp_user'] = 'user';
        $mail_config['smtp_pass'] = 'pass';
        $mail_config['smtp_port'] = '587';
        $mail_config['smtp_timeout'] = 5;
        $mail_config['charset'] = 'utf-8';
        $mail_config['mailtype'] = 'html';
        $mail_config['wrapchars'] = 76;
        $mail_config['wordwrap'] = TRUE;
            
        $CI->email->initialize($mail_config);
        $CI->email->set_newLine('\r\n');
        
        if ($lang == "en"){    
            $CI->email->from('[email protected]', 'English Support');
        }else{
            $CI->email->from('[email protected]', 'Support en francais');
        }        
        $CI->email->to($email);
        if ($cc != null){
            $CI->email->cc($cc); 
        }    
        $CI->email->subject($subject);
        $CI->email->message($message);    
        if ($file != null){
            $CI->email->attach($file);    
        }    
        //$CI->email->print_debugger();
        return $CI->email->send();            
    }
}

पुस्तकालय पुस्तकालय / Alerter.php

class Alerter {

    public function alert_user($user_email, $subject, $message, $lang) {
        //load helper
        $this->load->helper('sendEmail');
        //using helper
        sendEmail($user_email, $subject, $message, $lang);
    }
    
    public function alert_admin($admin_email, $subject, $message, $lang, $reason){
        //load helper
        $this->load->helper('sendEmail');
        .....
        //using helper
        sendEmail($admin_email, $subject, $message, $lang);
        .....
    }
}

नियंत्रक

class Alerts extends CI_Controller {
    function __construct() {
        parent::__construct();
    }  

    public function send_alert($userid) {
        
        //load library and model
        $this->load->library('Alerter');
        $this->load->model('alerter_model');
        
        //get user
        $user = $this->alerter_model->get_one_by_id($userid);
        
        //using library
        $this->Alerter->alert_user($user->email, $subject, $message, $lang);

    } 
}

सहायक

ऑटोलैड आपके सहायक कार्य करता है। यदि आप अपनी परियोजना में कई समय का उपयोग करते हैं

$autoload['helper'] = array('url', 'form');

देखने में प्रपत्र सहायक का उपयोग करें

<?php echo form_open('Public/Login/loginAuth'); ?>

<?php
       echo "<div class='row'>";
       echo "<label for='inputEmail' class='col-lg-2 control-label col-lg-offset-2 col-md-2 control-label col-md-offset-2 col-sm-2 control-label col-sm-offset-2'>Enter Email</label>";
       $email = array(
          "name"=>"email",
          "placeholder"=>"Email",
          "class"=>"form-control"
          );

     echo "<div class='col-lg-6 col-md-6 col-sm-6'>";
     echo form_error('email');
    echo form_input($email)."<br/>";
  echo "</div>";
echo "</div>";

echo "<div class='row'>";
    echo "<label for='inputPassword' class='col-lg-2 control-label col-lg-offset-2 col-md-2 control-label col-md-offset-2 col-sm-2 control-label col-sm-offset-2'>Enter Password</label>";
  $password = array(
    "name"=>"password",
    "placeholder"=>"Password",
      "class"=>"form-control"
    );

  echo "<div class='col-lg-6 col-md-6 col-sm-6'>";
    echo form_error('password');
    echo form_password($password)."<br/>";
  echo "</div>";
echo "</div>";

echo "<div class='row'>";
  
  $submit = array(
    "name"=>"submit",
    "value"=>"Submit",
    "class"=>"btn btn-primary col-lg-offset-9 col-md-offset-9 col-sm-offset-9 col-xs-offset-9"
    );
  echo form_submit($submit)."<br/>";

echo "</div>";

?>



Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow