ObjectHTML
Information from The State of Sarkhan Official Records
ObjectHTML: Object-Oriented HTML Generation for PHP
ObjectHTML empowers you to create HTML structures in an intuitive, object-oriented manner. It offers classes for common HTML tags, Bootstrap elements, and utility classes to simplify HTML generation in your PHP projects. It was an integral part and core functionality are extracted from SPKZ's Web Application Framework and turned into public use, PSR-4 Compliant PHP library.
ObjectHTML has been ported to Laravel compatible format for Mex School Management Software but was eventually deprecated along with the WAF itself.
🚧 Under Construction: | This page is currently under construction, and by "under construction", we mean it's in a black hole of procrastination from which no page has ever escaped. Fear not, intrepid internet explorer! This page will be finished... eventually. Maybe. Possibly. Probably not. But who knows, right? Stay tuned for updates, or don't. We won't judge. |
---|
Alright, let’s dive into the mystical world of **ObjectHTML**—where PHP meets HTML and gets all fancy with object-oriented magic! Buckle up; this is gonna be a wild ride. --- # **ObjectHTML: Elegant HTML Generation for PHP Developers** **Introduction** In the land of PHP development, generating HTML dynamically can often feel like herding cats—messy, chaotic, and a little unpredictable. Enter **ObjectHTML**—a PSR-4 compliant PHP library that brings order to the madness by letting you create HTML elements in an elegant, object-oriented manner. Originally a core component of the **SPKZ Web Application Framework**—a relic of a time when frameworks roamed the earth like dinosaurs—ObjectHTML has since been refined and released for public use. Though the SPKZ framework (and its Laravel-compatible fork for Mex School Management Software) met the same fate as all software eventually does—deprecation—ObjectHTML still stands as a testament to cleaner, maintainable code. --- ## **Why Use ObjectHTML?** Traditional PHP approaches to HTML generation often result in code that’s about as legible as an eldritch curse. Mixing HTML strings with PHP logic leads to code that is hard to read, maintain, and debug. ObjectHTML solves this by providing a consistent interface to generate markup using PHP objects. Imagine swapping this mess: ```php echo '<div class="btn-group-vertical">'; echo '<button class="btn btn-primary">Generate Invoice</button>'; echo '<button class="btn btn-info">Print PDF</button>'; echo '<button class="btn btn-success">Add Students</button>'; echo '</div>'; ``` For a cleaner, OOP-style approach: ```php $bg = Extra_BootstrapElements::quickDiv('btn-group-vertical'); $btnGenInv = Extra_BootstrapElements::btnWithGlyphico('cmdGenInv', 'btn-primary', 'list-alt', 'Generate Invoice'); $btnPrintPDF = Extra_BootstrapElements::btnWithGlyphico('cmdPrintPDF', 'btn-info', 'print', 'Print PDF'); $btnAddStudents = Extra_BootstrapElements::btnWithGlyphico('cmdAddStudents', 'btn-success', 'user', 'Add Students'); $bg->append($btnGenInv); $bg->append($btnPrintPDF); $bg->append($btnAddStudents); echo $bg; ``` **ObjectHTML** isn’t just sugarcoating—this structured approach makes the code easier to test, extend, and understand. --- ## **Deep Dive into ObjectHTML: Example Usage** Here’s a look at some sample methods from ObjectHTML: ### **1. The `monthInfoCmds` Method** This method is designed to create a vertical button group with dynamic options based on the `$monthID` parameter. ```php public function monthInfoCmds($monthID) { $mRow = $this->getMonth($monthID); $mID = $this->id . "-" . $monthID; $bg = Extra_BootstrapElements::quickDiv('btn-group-vertical'); $btnGenInv = Extra_BootstrapElements::btnWithGlyphico( 'cmdGenInv-' . $mID, 'cmdGenInv btn-primary btn-raised btn-sm', 'list-alt', 'สร้าง Invoice' ); $btnPrintPDF = Extra_BootstrapElements::btnAWithGlyphico( 'cmdPrintPDF-' . $mID, 'btn-info btn-raised btn-sm', 'print', 'PDF เช๊คชื่อ', route('mt.month.pdf', [$this, $monthID]) ); $btnPrintPDF->setTarget('_blank'); $btnAddStudents = Extra_BootstrapElements::btnWithGlyphico( 'cmdAddSub-' . $mID, 'cmdAddSub btn-success btn-raised btn-sm', 'user', 'เพิ่มนักเรียน' ); if (!$mRow) { $btnGenInv->setDisabled(); $btnPrintPDF->addClass('disabled'); } $bg->append($btnPrintPDF); $bg->append($btnGenInv); $bg->append($btnAddStudents); return $bg; } ``` 👉 **Explanation:** - Creates a button group using Bootstrap classes. - Dynamically generates buttons based on conditions. - Uses `setDisabled` and `addClass` methods for conditional styling. ### **2. The `monthInfoTable` Method** This method generates a responsive table layout using ObjectHTML’s utilities. ```php public function monthInfoTable() { $tbl = new Tag_Table(); $trh = new Tag_TableRow(); $tbl->append(new Tag_TableHeader($trh)); return Extra_BootstrapElements::quickDiv('table-responsive', null, $tbl); } ``` 👉 **Explanation:** - Dynamically creates a responsive table using Bootstrap's `table-responsive` class. - Tag-based object creation ensures clean, organized code. --- ## **The Final Verdict** ObjectHTML is a love letter to PHP developers who crave structured, maintainable, and expressive HTML generation. It’s a powerful tool, especially if your project has complex or dynamic HTML requirements. While it may be a remnant of a bygone framework, its practicality remains. For those who still embrace PHP (and don’t scoff at it like some hipsters do), ObjectHTML is a great way to keep your code legible and elegant. You may no longer need to wrestle with spaghetti code—just roll out the red carpet and let ObjectHTML strut its stuff. --- ## **Epilogue: The OOP Dream for HTML** ObjectHTML’s legacy lives on, even if its parent framework was lost to the sands of time. Whether you’re whipping up web apps or just tired of writing raw HTML in PHP, ObjectHTML’s approach might just be your new best friend. So, ready to dive deep into the OOP madness, or are you the type to stick with good ol’ echo and print? 😉