Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Creating a new view on an existing controller with a plugin.

Is it possible to create a new view for an existing controller from withing a plugin?

That is, say I want to create a new way of looking at categories. I could overwrite the default view with a custom one using a theme. But I want to give my users a choice of different views. How would I go about adding a custom view to the categories controller?

I have gotten as far as creating a plugin with the following function:
public function CategoriesController_Render_Before($Sender) { //todo: implement view choice logic $Sender->View = "anewwaytolookatthings"; }

This just gives me a view not found error. Even if I put a file called "anewwaytolookatthings.php" in my plugins folder.

Thoughts?

Search first

Check out the Documentation! We are always looking for new content and pull requests.

Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Tagged:

Best Answer

Answers

  • I have made it a few steps farther. I can override a function on an existing controller like so:
    public function CategoriesController_Index_Create($Sender) {

    Now how can I access data thrown to the original function?
    public function Index($CategoryIdentifier = '', $Page = '0') {

    I figured out I can use:
    public function CategoriesController_Index_Create($Sender, $CategoryIdentifier = '', $Page = '0') {

    Everything seems to be working well, other than having to replace $this with $Sender if I want to access the overridden controller's members.

    Is there anything else I am missing?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Sorry, I got a bit confused, what is your current progress? have you managed to do what you were looking for, or do you still get errors?

  • I still haven't found an answer to my original question, but I figured out how to override the default Categories Controller function. Hopefully this will lead somewhere profitable.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Ok. You could try using FetchViewLocation() to get the view and give it to the Sender.

    $Sender->View = $Sender->FetchViewLocation('myalternativeview', '', 'plugins/MyPlugin');

    Please note I haven't tested the above, this is just am 11:30 PM idea. :)

  • That gave me the error "View not found" which is the same issue I had initially.

    Thanks for the help anyway @businessdad :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Sad that I was had the solution, but it didn't work because I didn't have the extension. Slapping myself for not thinking about it.

    Thanks @x00 and @businessdad for your help!

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.