လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> costigner အတွက်အထောက်အကူပြုလုပ်ဆောင်ချက်များနှင့်အတူ cosh ၏ encapsulations

costigner အတွက်အထောက်အကူပြုလုပ်ဆောင်ချက်များနှင့်အတူ cosh ၏ encapsulations

gitbox 2025-05-28

PHP ကို ​​အသုံးပြု. 0 က်ဘ်အပလီကေးရှင်းများကိုတီထွင်သည့်အခါ Cosh () function ကို sthemolic cosine, စံသင်္ချာ function ကိုတွက်ချက်ရန်အသုံးပြုသည်။ PHP သည်ဤလုပ်ဆောင်မှုနှင့်အတူပါ 0 င်သော်လည်း cadignigner မူဘောင်ကိုအသုံးပြုသောအခါ၎င်းသည်စီမံကိန်းတစ်လျှောက်လုံးပြန်လည်အသုံးပြုရန်အတွက်အထောက်အကူများအဖြစ်ဘုံလုပ်ဆောင်မှုများကို encapsulate လုပ်ထားလေ့ရှိသည်။ ဤဆောင်းပါးသည် coverigniter အတွက် cosh () function ကို undertate နှင့်အသုံးပြုနည်းကိုရှင်းပြပါလိမ့်မယ်။

အဆင့် 1: Helper File ကိုဖန်တီးပါ

ပထမ ဦး စွာကျွန်ုပ်တို့သည်ထုံးစံအထောက်အကူပြုဖိုင်ကိုဖန်တီးရန်လိုအပ်သည်။ Camiginiter Constander ကို Constionigner_helper.php ဖိုင်ကိုသင်အမည် ပေး. application / mather / directory တွင်သိမ်းဆည်းနိုင်သည်။

 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * math_helper.php
 * စိတ်ကြိုက်သင်္ချာ function ကိုလက်ထောက်
 */

/**
 * hyperbolic cosine တန်ဖိုးတွက်ချက်
 *
 * @param float $value
 * @return float
 */
if ( ! function_exists('cosh_safe')) {
    function cosh_safe($value) {
        if (!is_numeric($value)) {
            return false; // သို့မဟုတ်ချွင်းချက်ချပစ်
        }
        return cosh($value);
    }
}

အထက်ပါကုဒ်တွင် function_exists များကို function_exists ကို အသုံးပြု. function tensefinition ကိုရှောင်ရှားရန်နှင့်ကြံ့ခိုင်မှုကိုမြှင့်တင်ရန် input အပေါ်အခြေခံသည့်စစ်ဆေးမှုများကိုလုပ်ဆောင်ရန်။

အဆင့် 2: Helper ကိုတင်ပါ

ဒီ function ကိုမသုံးမီ, သင်သည်ဤအထောက်အထားကို Controller သို့မဟုတ်မော်ဒယ်တွင်တင်ရန်လိုအပ်သည်။

 $this->load->helper('math');

လျှောက်လွှာတစ်လျှောက်လုံးတွင်၎င်းကိုအမြဲတမ်းရရှိနိုင်ပါက၎င်းကို လျှောက်လွှာ / config / autoload.php ဖိုင်တွင် Autoload (Helper '] array သို့ထည့်နိုင်သည်။

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

အဆင့် 3: Controller သို့မဟုတ် View ကိုခေါ်ပါ

တစ်ချိန်ကကူညီမစတဲ့အတွက် chosh_safe () function ကို controller ဒါမှမဟုတ် view မှာတိုက်ရိုက်လို့ခေါ်တယ်။

 $value = 2;
$result = cosh_safe($value);
echo "cosh({$value}) = {$result}";

လက်တွေ့ဇာတ်လမ်းဥပမာများ

သင်တွက်ချက်မှုစာမျက်နှာတစ်ခုကိုတီထွင်နေပြီး hyperbolic cosine ရလဒ်များကို output လုပ်ရန်လိုအပ်ပါသည်ဆိုပါစို့။

 <form method="post" action="https://gitbox.net/index.php/math/calculate">
    <input type="text" name="number" placeholder="နံပါတ်ထည့်ပါ">
    <button type="submit">ရေတွက် cosh</button>
</form>

Controller Code:

 public function calculate() {
    $this->load->helper('math');
    $number = $this->input->post('number');
    $result = cosh_safe($number);
    echo "ရလဒ်ကတော့: " . $result;
}

အကျဉ်းချုပ်

cosh () function ကို chainer function တစ်ခုအဖြစ် encapsulating အားဖြင့်ကျွန်ုပ်တို့သည် code ကိုပြန်လည်သုံးသပ်ခြင်းကိုတိုးတက်အောင်မလုပ်နိုင်ပါ, cutignigner တွင်ထိုကဲ့သို့သော encapsulation များသည်အလွန်များသောအားဖြင့်အထူးသဖြင့်သင်္ချာဆိုင်ရာသို့မဟုတ်ယုတ္တိရှိသည့်အပြောင်းအလဲများအတွက်အကြံပြုသည်။ ဤဆောင်းပါးသည်သင်၏စီမံကိန်းအတွင်းရှိကိရိယာကိရိယာများကိုပိုမိုကောင်းမွန်စွာစုစည်းရန်ကူညီပေးပါ။