Gilko
Gilko

Reputation: 2407

cakephp 3.0 Can an element have it's controller?

I have an element in 'src > Template > Element' called contact.ctp.

Is it possible for the 'contact.ctp' to have its own controller?

In 'src > Controller' I made an ElementController.php with a contact action inside it. Strange thing is that the functionality of sending an email doesn't work in this case

When I make a folder called Contact with inside a index.ctp file and in my controllers folder I make a ContactController.php with a index action inside it. Al the functionality in this case works.

Is it possible for elements to have their controllers?

Upvotes: 2

Views: 687

Answers (1)

ADmad
ADmad

Reputation: 8100

No, elements can't have their own controller. But you can for e.g. set $this->view = '/Element/contact'; in your controller action to make it use an element. Though in your particular case I don't see the benefit of using an element instead of regular action template.

You might also want to check out View Cells and Forms.

Upvotes: 3

Related Questions