0

Here I developed a nano system to publish thoughts in a diary, very simple, but functional for the need. The content is in a Json structure and there would be a need to change the aesthetics of the diary through themes. This way, I created a custom view that loads json, converts it to HTML and takes the theme chosen by the user, renders it and sends it to the browser.

Due to the possibility of having countless themes, I decided to create a directory in /src with the name themes and within it each directory is a different theme with the content being the same structure as the /templates directory in cakephp.

Everything works perfectly. But, out of necessity, to deploy it to the existing cakephp website as well, I decided to transform it into a cakephp plugin. I loaded this plugin. I configured the mysite.com/diary/ routes for this plugin. This way, the diary system works fine, until there is an error that requires me to return a personalized error page that is in the chosen theme.

Previously it worked normally, if there was any error, it would load the specific template within the /Error directory of the chosen theme to display the message. But as a plugin, when an error occurs, cakephp ignores my custom view and shows errors in the /templates directory or in the core itself.

In the plugin, I load the view with:

$this->viewBuilder()->setClassName('diary.myview');

Previously, the view was AppView.php with customized rendering.

And maybe that's the point. In the plugin I have to indicate the view, but in the main app the view is loaded automatically. And I didn't want to change anything in the core's default view or /src/view/AppView.php itself because there is something else running there. The idea is that everything would have to be isolated within the plugin.

3
  • Hey @Jootah, while I can't answer from the top of my head, what helps me if I get stuck is looking at how other CakePHP plugins do the things I'm stuck with. After an odd hour, I am normally able to figure out a good way to do whatever I'm trying to do. In your case maybe you'll find answers in FriendsOfCake/crud-view or FriendsOfCake/crud? Commented Jul 18, 2024 at 10:49
  • isnt the name case sensitive? So $this->viewBuilder()->setClassName('Diary.MyView'); etc? Commented Jul 26, 2024 at 10:16
  • But as for your issue: I would imagine you can add your own custom error handler which would then be able to be "Plugin" aware. Commented Jul 26, 2024 at 10:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.