Jump to content

Repeater Page Classes [Dev Version 3.0.152]


Patrik97
 Share

Recommended Posts

Since i am using Repeaters in nearly every project, i would like to know if i could use PageClasses with Repeater Pages.

The repeater template is called: " repeater_files";

I tried

class RepeaterFilesPage extends Page {

and

class RepeaterFilesRepeaterPage extends RepeaterPage {

both aren't working.

I changed the filename to the classname in both cases.

Also what do you think about using PageClasses as Models and doing data related operations only through them?

Link to comment
Share on other sites

@Patrik97
Welcome to the forum.

RepeaterPageArray object represents the value of a repeater field, related to the page where the repeater lives in.

A single item of this PageArray is an instance of class RepeaterPage. The class is set via FieldtypeRepeater::getPageClass(). This value is not changeable, the function not hookable. If you want to use a custom class for your repeater item objects with additional methods or properties, you need to create your own Fieldtype, derived from FieldtypeRepeater which includes your custom class and overwrites the getPageClass() function. Example where exactly this is done: FieldtypeRepeaterMatrix

Maybe related:

 

 

  • Like 1
Link to comment
Share on other sites

Hi @Patrik97 It might be worth you saying what you're trying to achieve.

The kind of approach you describe would only rarely be necessary, though you may have particular needs.

I'm wondering if there might be a much easier way of doing things.

 

  • Like 1
Link to comment
Share on other sites

Thank your for your replies.

As allotted to in the last sentence of my post i would like to use the Page classes as Models (as you would in an MCV framework) and the template files as controllers.

It seems to me like this would greatly improve the overall Project strucutrure.

Also i think testing should be way easier through theese page functions rather than url calls.

Link to comment
Share on other sites

Just my personal view, but PW isn't an MVC framework, so trying to make it behave like one doesn't really sound like a good plan. My guess is that you'd end up making things very difficult for little benefit. I'd suggest going about projects in a PW-like way unless there's a particular reason not to.

For testing, there are lots of tools out there, e.g. https://www.cypress.io/, and you might find this module useful: https://modules.processwire.com/modules/process-nette-tester/

And I'd strongly recommend this module: https://modules.processwire.com/modules/tracy-debugger/

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...