Jump to content

Create controllers not associated with templates and use them to render pages


Ivan Gretsky
 Share

Recommended Posts

Good day @teppo and all the Wireframe fans!

I am creating an authorization system to restrict some pages from unauthorized access. It should work like this. At some point in the page rendering process the code should check user auth (not PW native) and either proceed with normal page rendering process or show an authorization form. The auth form should render at the same url as the normal page and should have access to this page's data and custom methods. But it looks completely different and should have custom methods of its own. That's why I want to take the page object and render it with another Wireframe controller/layout/view. This controller should not be connected to any PW template and should have some independent name. How can I do it? Please help!

P.S. I have some templates working under Wireframe and some with their own template files. But the authorization system should be based on wireframe and work for both of these. That kind of limits the possible options (like having a common trait in all Wireframe controllers) if I understand it correctly.

Link to comment
Share on other sites

On 3/15/2023 at 7:21 PM, Ivan Gretsky said:

This controller should not be connected to any PW template and should have some independent name. How can I do it? Please help!

Personally I would consider an alternative approach, having this auth form as a separate page that you pass the original page to. This way you could have it as a separate entity, but still have access to anything that the original page contains.

In this scenario you could have the original page fetch and then render the authorization form page, and return rendered content from there, instead of content of its own. Though of course I may be missing plenty of nuance in your use case 🙂

In case it makes more sense, it is also possible to set/override the controller for a page (by calling $page->setController('TemplateName')) just like it is possible to set/override layout or view. Technically this might mean that while rendering a page you detect this situation and then re-render the same page with different controller. Feels a little odd, and I'm not entirely certain that it'll work, but I can't see why it wouldn't either.

  • Like 1
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...