มีอะไรใหม่ในเวอร์ชั่น 1.2

อัพเดตเวอร์ชั่น 1.2

Framework MVC

เนื่องจากในปัจจุบันการทำงานในรูปแบบ MVC (Model View Controller) เป็นส่วนสำคัญที่ช่วยให้การทำงานง่ายขึ้น และไม่ซับซ้อน ทำให้การแบ่งการทำงานของโค้ด และการแสดงผลตอบโต้กับผู้ใช้งานทำได้ง่ายขึ้น

ค่าคงที่ ที่เพิ่มเข้ามาในเวอร์ชั่นนี้คือ

Application/Config/Route.php
DEFAULT_CONTROLLER_ROUTE
DEFAULT_ACTION
System/Core/QLipe.php
Q_CONTROLLER
Q_ACTION
Q_PARAMS
  1. DEFAULT_CONTROLLER_ROUTE และ DEFAULT_ACTION - เปรียบเสมือน Addon เนื่องจากไม่ได้เป็น Config ที่มีในระบบ แต่เป็น Config ที่นำมาใช้ในไฟล์ Application/Public/Index.php และสำหรับใครที่ไม่ต้องการใช้ระบบ MVC เราจะกล่าวถึงในหน้าถัดไป

  2. Q_CONTROLLER , Q_ACTION และ Q_PARAMS - เป็นค่าคงที่ ที่เกิดขึ้นในไฟล์ System/Core/QLipe.php และสามตัวแปรนี้เกิดขึ้นมาเพื่อทำระบบ MVC โดยเฉพาะ

New Helpers

ชื่อ Helper

ฟังก์ชั่นใน Helper

Array

array_get()

Cookie

set_cookie()

get_cookie()

del_cookie()

File

dir_get()

write_file()

del_files()

get_file_info()

ThrowError (Autoload)

throw_error()

Url (Autoload)

base_url()

redirect()

การใช้ array_get()

เป็นฟังก์ชั่นสำหรับการถึงเข้า Array ดูตัวอย่าง

<?php 
    $app = new App;
    $app::render(function() {
        $app->load->helper('Array');
        
        $datas = [
            'Id1'    =>    [
                'Fullname'    =>    'Kittichai Mala-in'
            ]
        ];
        
        echo array_get('Id1.Fullname', $datas); // echo : Kittichai Mala-in
        
        echo array_get('Id1->Fullname', '->', $datas); // echo : Kittichai Mala-in
    });
?>

ค่า Arguments ที่ส่งเข้าไปให้ array_get()

  1. $arrayTarget - String ที่ใช้ในการเข้าถึงตัวแปรที่ต้องการ ในตัวอย่างคือเข้าถึง Id1 และ Fullname ที่อยู่ใน Id1

  2. $break - คือตัวแยกระหว่าง Index ของ Array ถ้าไม่กำหนด (ตามตัวอย่างในบรรทัดที่ 12) ก็จะได้เป็นค่า Default คือ จุด

  3. $arrayToSearch - ตัวแปร Array ที่ต้องการเข้าถึง

ค่า Aruguments ที่ส่งเข้าไปเหมือนกันกับ setcookie()https://www.php.net/manual/en/function.setcookie.php

เป็นฟังก์ชั่นสำหรับการดึงข้อมูลของ Cookie ค่า Arguments ที่ส่งเข้าไปให้ get_cookie()

  1. $cookieName - ชื่อ Cookie ที่ต้องการดึงข้อมูล

เป็นฟังก์ชั่สำหรับลบ Cookie ค่า Arguments ที่ส่งเข้าไปให้ del_cookie()

  1. $cookieName - ชื่อ Cookie ที่ต้องการลบ

Last updated

Was this helpful?