Closed kousar2334 closed 4 years ago
When the $data
is rendered it is a full html structure, so I suggest not to pass it to a blade view file since it is already a full webpage. There are multiple ways to render the data from one page, you could do this:
use PHPageBuilder\Theme;
use PHPageBuilder\Modules\GrapesJS\PageRenderer;
use PHPageBuilder\Repositories\PageRepository;
public function viewPage($pageId)
{
$theme = new Theme(config('pagebuilder.theme'), config('pagebuilder.theme.active_theme'));
$page = (new PageRepository)->findWithId($pageId);
$pageRenderer = new PageRenderer($theme, $page);
$html = $pageRenderer->render();
return $html;
}
I have copied the function but there is an error. Error Call to a member function findWithId() on null http://127.0.0.1:8000/admin/pages/1
On what line of the code does this error occur? Can you further trace where it went wrong, this error does not reveal to me what causes it.
public function findWithId($id)
{
return $this->createInstance($this->db->findWithId($this->table, $id));//the error is occur this line
}
Ok that shows me what is the issue, the DB is not instantiated. This makes sense because this is done when we create a PHPageBuilder instance, which we did not do. I just committed a fix to the master which will be part of the next release.
For now you can add this to the boot method of your App\Providers\AppServiceProvider
:
$this->app->singleton('phpPageBuilder', function($app) {
return new PHPageBuilder(config('pagebuilder'));
});
$this->app->make('phpPageBuilder');
there is an error.
Yes everytime you create an instance of a class that is not inside the current folder, you need to include it with use [namespace]
. If you switch to an editor like PhpStorm it warns you of this and helps to fix it. In this case you need to add:
use PHPageBuilder\PHPageBuilder;
it works. thank you so much.
public function viewPage($pageId) { $data=DB::table('pagebuilder__pages')->where('id',$pageId)->value('data'); return $data; } I get the page data from the function, How can I render the data into blade?
When the
$data
is rendered it is a full html structure, so I suggest not to pass it to a blade view file since it is already a full webpage. There are multiple ways to render the data from one page, you could do this:use PHPageBuilder\Theme; use PHPageBuilder\Modules\GrapesJS\PageRenderer; use PHPageBuilder\Repositories\PageRepository; public function viewPage($pageId) { $theme = new Theme(config('pagebuilder.theme'), config('pagebuilder.theme.active_theme')); $page = (new PageRepository)->findWithId($pageId); $pageRenderer = new PageRenderer($theme, $page); $html = $pageRenderer->render(); return $html; }
Where write this code ?
You can make a Laravel controller method with this snippet.
public function viewPage($pageId) { $data=DB::table('pagebuilder__pages')->where('id',$pageId)->value('data'); return $data; } I get the page data from the function, How can I render the data into blade?