Issue #2234💬 AnsweredOpened August 30, 2019by arievanden0 reactions

I/O operations with PHP/MySQL - I'm stuck

快速解答by smik3

Is there any reason why you can't use PHP to save it directly as a JSON file rather than on the database?

Read full answer below ↓

Question

Hello and thank you for GrapesJS. It's awesome. I do have a question that I haven't been able to find an answer to. I'm using PHP/Yii and MySQL db.

Your example for external storage config:

代码片段TEXT
> storageManager: {
    type: 'remote',
    urlStore: 'http://endpoint/store-template/some-id-123',
    urlLoad: 'http://endpoint/load-template/some-id-123',    
  }

> {
  // `gjs-` is the id prefix
  'gjs-components': [{ tagName: 'div', ... }, {...}, ...],
  'gjs-style': [{...}, {...}, ...],
}

My problem is that I'm trying to get the HTML to JSON conversion formatted properly before saving to the db record so we can pull it up again from urlLoad. I can't find ANY clear examples of how to do this from PHP. I could try using the Firestore plugin and save myself the trouble, but I thought I'd ask if there were any clear examples of how to do I/O operations with PHP/MySQL.

Maybe using HTML-5 html2json (http://masterminds.github.io/html5-php/) would help? Or does GrapesJS automatically do the HTML to JSON/DOM conversion on the fly? It's not clear to me from the docs.

Answers (3)

smik3September 3, 2019

Is there any reason why you can't use PHP to save it directly as a JSON file rather than on the database?

arievandenSeptember 4, 2019

I probably could, but we need to saved to DB. I'm OK, a developer figured it out for me, but it would be great to have some more detailed code examples for use with php/mySQL. Your docs are great, but this would be a nice addition to your docs section.

artfSeptember 6, 2019

My problem is that I'm trying to get the HTML to JSON conversion formatted properly

GrapesJS, by default, generates 4 types of data: HTML, CSS, Components (JSON from HTML), Styles (JSON from CSS) So you shouldn't do any kind of conversion... it's explained here https://grapesjs.com/docs/modules/Storage.html#store-and-load-templates

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.