Welcome Guest, Not a member yet? Register   Sign In
Widgets that can have links to themselves
#1

[eluser]breaddes[/eluser]
I know a widget actually can't have a link to methods of itself because it's just a »slave« of a controller. I only can post it back to itself and process the input like the $_POST vars. The widget must then decide for itself what to do with the input.

The problem is that I have something that is very much widget-like from it's appearance and reusabilty. View-wise it is a DIV with a collection of links. Whenever a link is clicked the view should be replaced by a matching other view. This should be kind of a intelligent partial.

This partial is like a component. It can be used in different other views depending on whether it's needed or not.

Now it's clear that there must be something more than just the partial view. If a link get's clicked where do I process that link? I mean logically it must be in the current controller because globally I don't wanna go somewhere else unless there would be a redirect to my site back.

Are there any best practise example for a situation like that? I go round in circles and can't find a way out.
#2

[eluser]WanWizard[/eluser]
Why not? Everything is possible.

ExiteCMS (which is completely build out of widgets) uses a 'widget-id' in the link to determine which controller (we use Modular CI, so we're not restricted to a single controller) needs to process the request. For forms, both a 'widget-id' and a form name is used to support multiple forms per widget.

The widget itself never sees this information. The HTML front controller strips it, and only passes the URI segments to the correct controller method, identified by the id.
#3

[eluser]breaddes[/eluser]
[quote author="WanWizard" date="1286308593"]The widget itself never sees this information. The HTML front controller strips it, and only passes the URI segments to the correct controller method, identified by the id.[/quote]

What I do at the moment is something similar or I think so:

Code:
site/page/5/?widget=links&method=changeview&param=link4

My front controller loads /site/page/5 as usual (That's my site without any modules or widgets). Any widgets are optional so if there are those $_GET params I additionally load the module.

The thing is it doesn't feel that right because it's mixed Query String and Segments
#4

[eluser]WanWizard[/eluser]
Nobody stopping you from using:
Code:
site/page/5/links/changeview/link4
instead. Wink

At the point where you load/call your widget code, check the number, and if a match, pass the remainder to the widget. If not, don't pass anything.
#5

[eluser]breaddes[/eluser]
First, thanks for your answers! I really appreciate it.
There is one problem with my url segments. They are not always of the same length. So there is no certain position where I can look for the widget. That is why I mixed segments and request strings.
#6

[eluser]breaddes[/eluser]
Is there any remedy to this. I mean I could have many url segments:

Code:
site/page/5/6/8/9/1/2/numberx/numbery/links/changeview/link4/link3

How do I know which part is my module? I can only think of running through all of my segements and check if one is a module.
#7

[eluser]WanWizard[/eluser]
You're the one that designs the website, so you have total control about how every link is generated. So invent a URL standard, and stick to it.

In my case, folders and pages in my website may not be numeric only. So the first segment that is numeric is the element number (I don't use a widget number, because the same widget could be placed on a page multiple times), the remaining segments are parameters for the widget.
#8

[eluser]breaddes[/eluser]
This is how I do it now in my front controller:

Code:
//Check if there's another Controller after segment 1. Then it must be a Module
        foreach($this->uri->segments as $segment){
            if(checkController($segment) && array_search($segment , $this->uri->segments) > 1){
                $module_url = implode("/", array_slice($this->uri->segments, array_search($segment , $this->uri->segments)-1));
            }
        }
#9

[eluser]WanWizard[/eluser]
If it works for you, why not?

In my case it's a bit more complicated, because a widget is actually a module controller method. A module can have multiple controllers, each having lots of 'exported' methods. And most widgets are configurable and can be placed multiple times on a single page. So I needed a method not to be able to identify a widget in the URI, but that specific widget on that specific page. A unique number pointing to that specific instance of a widget was the easiest solution.
#10

[eluser]Unknown[/eluser]
is there any tutorial on setting up and using modular ci? or creating a sample widget in that matter




Theme © iAndrew 2016 - Forum software by © MyBB