Using Plugin Data in Theme Plugin

i’m fairly new to Cake, and i’m facing the following logical problem for me:

I’ve created a Theme as a Plugin for my Cake Site, in which i created a layout for the home page (home.ctp) and a layout for the default pages (default.ctp). Now i’ve further created a simple appointments plugin. My Question: How do i make the data from the appointment plugin available in theme plugin?

Thank you and Best Regards

You pass it from the controllers to the view.
eg. in your controller you have this:

class MyController extends AppController{
  public function index(){
    $this->set('cake','the cake is not a lie!'); // name first, then the value

then in your view (eg. plugins/CreamTheme/src/Template/MyController/index.ctp) you just display it using:

<?= h($cake); ?>

this will output the cake is not a lie! in the view!.

Thank you for your answer!

In my case, i need to use the appointment object from the apointment plugin in my theme plugin. Which means that i have no access to the appointments from the AppController inside the theme plugin. Is there some way to pass the appointments to my theme plugin?

You could try using a helper class?
Not sure if they are meant for that though…

Yeah, i had that idea aswell. I’m just stuck in how to do so. I just simply want to load all appointments inside one of my theme-views, and display them. I tried to create a helper in my plugin, named AppointmentHelper. In the docs i read that you can use a helper inside a plugin (the theme in my case) with

public $helpers = [‘Appointment.Appointment’];

But that is not getting me anywhere. I’d wish theming would be better documentend in Cake v3, it is a bit hard to see through as a beginner

public $helpers is not used anymore in CakePHP 3.x.
Instead, read this:

First of all, i’m using Cake 3.5.17, which comes with croogo, which i use.

All i want is to be able to use all my appointment data in the default view of my theme. My theme is a plugin called DefaultTheme. I am not even sure if a helper is the right thing to do this way, but as you suggested it too, i want to try it that way.

I’ve now created an AppView for my theme:


In this app i try to load the AppointmentHelper like this:

class AppView extends View


public function initialize()


This doesn’t make it available inside my view. Any idea?

I stumbled accross the ORM TableRegistry, and i’ve managed to find a solution for my problem:

I can access all my required data from the plugins table with the TableRegistry. In my Helper, i simply do:

$table = TableRegistry::getTableLocator()->get('Appointments');

    $appointments = $table->find()
            'status' => 1

and let the function return $appointments. Now i can use the data in my default view for my theme. It feels wrong though, if someone can help me to find a better way i’d approve.

What you are looking for is View Cells. Accessing the model layer from a helper is considered bad practise and breaks the MVC architecture.