How do I extend the application controllers with my own methods?

edited June 2011 in Development
As I want to make an addition to the registration process.

I was planning on doing this by extending a couple of core files...

* applications\dashboard\views\entry\registerapproval.php
* applications\dashboard\controllers\class.entrycontroller.php

... in a custom theme:

* themes\[theme]\views\entry\registerapproval.php
* themes\[theme]\controllers\class.entrycontroller.php

The view file is great. It loads in, and I can see my changes.

But I don't know how to handle the controller, including:

* What folder to put it in
* The controller declaration (ie CustomEntryController X extends EntryController)
* Anything else I haven't mentioned here
* Whether this is even possible with this approach

My plan was to overload RegisterApproval() and check that the DiscoveryText was in fact the answer to a question I was going to ask in the view.

It's not a particularly MVC approach (I see there are rules that could be set in the model) but I don't know Garden / Vanilla well enough yet. I'm happy to try anything else as well (hooks/events/Machine Elves) as I prefer to do things properly.



  • ToddTodd Chief Product Officer Vanilla Staff
    edited June 2011
    We actually have a way to block registrations with plugins specifically. Here's the code for your event handler:
    public function UserModel_BeforeRegister_Handler($Sender, $Args) {
    $User = $Args['User']; // Check this user...
    $Args['Valid'] = FALSE; // false blocks the registration
    To answer your specific question, unfortunately you can't override the RegisterApproval method because it is not called through the dispatcher. You could override the Register method which is what you are going to anyway. You do this with the following event handler:
    public function EntryController_Register_Override($Sender, $Args) { ... }
  • Great, thanks.

    In which classes is the above code supposed to reside?
  • You would put it in your plugin class. Take a peek at the plugin docs on the site. The method names are magic :)
  • Gotcha. I've written a couple of plugins, so hopefully this should be enough info.

    Ta :)
Sign In or Register to comment.