thenorman138 Posted July 13, 2018 Share Posted July 13, 2018 I'm creating a very lightweight interface that allows some users in our office to select predefined content (text, images, youtube/social links) or create their own text content using TinyMCE, and allow it to be viewed on different displays throughout the building. In concept it's fairly simple: The user chooses one of four templates that each have a banner and footer, and either 1,2 or 3 div elements inside the body for different content. Each of these is defined as a panel. The template links pull 1 of 4 php class files that houses the html templating for each page and then I'm assinging tags to each panel type. So I have panel types of Banner, Footer, FullWidth, HalfLeft, HalfRight, etc. So if a user chooses the full width template, it has a banner, a footer, and one full width container div (ID is fullWidth). Upon saving this, that means I'm saving three panels to the database (panel_type of banner, footer, or fullWidth) as well a page record, since the three panels make up one page that will be assigned to a display or displays. Would it make the most sense here to have a class for saving/adding panels and a separate class for saving/adding pages? In other words, when the save button is clicked, I'm at one time saving 3 panels that relate by foreign key to 1 page. At the same time this saves a reference to one or multiple displays. I'm basically asking, would I be better off to have one big class that saves all of this to the three respective tables, or should I call multiple classes, one for each part. Here's an example of a full width template: <div class="row top"> <div class="col-lg-12"> <div class="row" id="banner"> Banner Text </div> </div> </div> <div class="row middle"> <div class="col-lg-12"> <div id="fullWidth" > <textarea id="mytextarea"></textarea><!--This is the usage of TinyMCE for their text content--> <input type="submit" value="Save Data"> </div> </div> </div> <div class="row bottom"> <div class="col-lg-12"> <div class="marquee" id="footer">Footer Text</div> </div> </div> So they chose a template which calls a php file containing that above code (the html templating) and now upon submit I would call a 'save' class that saves the page record and assigns the 3 panels with a foreign key to the page ID. Does this sound like a decent approach to this? Quote Link to comment https://forums.phpfreaks.com/topic/307500-help-structuring-a-very-lightweight-cms-of-sorts/ Share on other sites More sharing options...
requinix Posted July 14, 2018 Share Posted July 14, 2018 If you want a very simple solution, serialization. The panel classes don't do anything except implement Serializable, and the database saving/restoring code simply un/serializes the objects as needed. They get serialized into a string which you can store directly. It's not searchable in the database, but I don't think the nature of this problem really lends itself to searching anyways. Adding Serializable means a little more work because if the classes might possibly change implementations in the future then non-Serializable classes can break: if stored in one form, changed in the code, then unserialized later you can get weird results. A common way to use Serializable would be like public function serialize() { return json_encode([ "v" => 1, "header" => $this->header, "fullWidth" => $this->fullWidth, "footer" => $this->footer ]); } public function unserialize($string) { $array = json_decode($string, false); switch ($array["v"]) { case 1: default: $this->header = $array["header"] ?? ""; $this->fullWidth = $array["fullWidth"] ?? ""; $this->footer = $array["footer"] ?? ""; break; } } Should the class need to change in the future you update the methods accordingly. public function serialize() { return json_encode([ "v" => 2, "banner" => $this->banner, "fullWidth" => $this->fullWidth, "marquee" => $this->footer ]); } public function unserialize($string) { $array = json_decode($string, false); switch ($array["v"]) { case 1: $this->banner = $array["header"]; $this->fullWidth = $array["fullWidth"]; $this->marquee = $array["footer"]; break; case 2: default: $this->banner = $array["banner"] ?? ""; $this->fullWidth = $array["fullWidth"] ?? ""; $this->marquee = $array["marquee"] ?? ""; break; } } Quote Link to comment https://forums.phpfreaks.com/topic/307500-help-structuring-a-very-lightweight-cms-of-sorts/#findComment-1559677 Share on other sites More sharing options...
thenorman138 Posted July 14, 2018 Author Share Posted July 14, 2018 Oh thank you, that's a big help! I'm treating this similar to WordPress inserting content into certain divs of a theme basically. So every display will call a display.php page with the relative content from the database, if that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/307500-help-structuring-a-very-lightweight-cms-of-sorts/#findComment-1559693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.