Search code examples
phpmodel-view-controllercontrollers

PHP: display a page by calling controller in another controller


I have a controller that displays a page depending on whether a user has already signed up for something when initially registering for the site.

If their organisation has already been registered, the page shows their profile which they can edit etc. (That bit works fine) But if they haven't the page is supposed to show a registration page where they can sign up

I've done this using:

$this->call('\Controllers\RegisterOrgController');

The user has an option of a free basic package, or a premium/premium plus package, which will require the user to be redirected to a payment page. My problem is, while this does show the registration page, it just registers the organisation when they choose 'premium' or 'premium plus' and doesn't show a payment page.

I know that it would be best to extend the organisation registration page from the profile page to get it to use the functionality; however, as the organisation profile page is primarily supposed to display a profile, I have it extending its own controller (from my recollection, you can't extend two classes) and using the register organisation controller to display the form.

I've seen ways to redirect pages in javascript, angularJS asp.net/C# but none of them have worked so far when adapted for PHP

I was thinking of setting the header:

header('location: ' . [function to get URL for new location]);

But this wouldn't work as the path is a subpath (register/organisation) and 'register' cannot be viewed if the user is logged in and the organisation profile has its own path name (organisation-profile).

TL;DR: it there a way to display a page by calling a controller that does this from another controller and still have the functionality, despite having a different path

Any help would definitely be appreciated, Thanks in advance!


Solution

  • Ok, so I figured out what I was doing wrong when it comes to the registration flow. My idea was ok, but the execution was terrible, so I thought I'd share the solution just in case anyone was having a similar issue (although this may be statistically unlikely)

    The Problem

    The registration process allowed the user to register an organisation either when they initially registered for the site, or after they had signed up and had their account verified. The registration page was not supposed to be view-able if the user was logged in; however, the organisation registration page stemmed from this page, which was causing a conflict as the paths were different.

    The Solution

    • Change the organisation profile controller to redirect to the organisation registration page instead of calling the registration controller.

    • Change the registration controller to show the page even if the user is logged in to keep the registration flow

    • In the go() function check the subpath of the page and if it is 'register', run the unauthenticated function to make sure the registration form doesn't ever show when logged in. This will allow you to follow the registration flow for an organisation but not have the registration page appear.

    Hope this helps anyone having a similar problem with their registration flow!