본문 바로가기

php 헛다리/CI4 헛다리

ci4 widget 위젯

728x90

 

ci4 widget 위젯

 

/app/Libraries/MyWidget.php

<?php

namespace App\Libraries;

class MyWidget
{

    private $parser; 

    public function __construct()
    {
        $this->parser = \Config\Services::parser(); // 파서 사용
    }


    public function test()
    {
        // 필요한 로직 작성 (데이터 가공, 모델 호출 등)

        $arr_VARIABLE_DATA['widget_data'] = "widget_0001";

        return $this->parser->setData($arr_VARIABLE_DATA, 'raw')->render("widgets/my_widget_view");
         // setData 에 raw 해야 html 태그 정상출력  / render( 출력파일 )
    }
}


/app/Views/widgets/my_widget_view.php
my_widget 위젯
<h1>{widget_data}</h1>

 

 

// 위젯 호출하는 파일

use App\Libraries\MyWidget;

public function dashboard_list()
{
    $widget = new MyWidget();
    $arr_VARIABLE_DATA['widget'] = $widget->test();

    return $this->parser->setData($arr_VARIABLE_DATA, 'raw')->render("layout_default");
}
?>

/app/Views/layout_default.php
{widget} <-- 위젯출력
728x90

'php 헛다리 > CI4 헛다리' 카테고리의 다른 글

ci4 session 세션  (0) 2024.10.10
ci4 쿼리빌더  (0) 2024.10.10
ci4 redirect함수  (0) 2024.10.10
ci4 라우터 url 설정  (0) 2024.10.10
ci4 에러 제대로 안뜰때  (0) 2024.10.10