Sending data to the layout

I am implementing the adminLTE layout for part ( or maybe all… ), of my project.

It is up and running, and I am switching to the adminLTE layout on a per action bases by adding the following code to my controller action.




// change layout for this page

$this->layout = 'adminlte';



That is working fine. My form is wrapped by the adminLTE layout.

Now I want to start activating all those wonderful goodies.

I figured I would start with something simple, like the user name.

So in my view, I create a block with the following code:




// get user name

$this->beginBlock('username');

    echo Yii::$app->user->identity->username;

$this->endBlock();



Then in the header.php file of the layout I add the following code in place of the hardcoded name of the user.




<?php if (isset($this->blocks['username'])): ?>

    <?= $this->blocks['username'] ?>

<?php else: ?>

    Unknown User!!!

<?php endif; ?>




This works just fine. However, I am expecting to have a LOT of stuff like this. The adminLTE has a lot of goodies, and some of them are going to be rather complex. They are also going to be the same for all pages.

I am thinking that widgets would be the best way to do this. But I have not done anything much with widgets yet.

Can I do pretty much anything with a widget that I can do with a controller and its associated views?

What sort of directory layout should I use for these widgets to keep them together. I may want to package them up at some point.

I was thinking something like





  basic

  |

  +--components

     |

     +--adminLTE

        |

        +--userinfowidget

        |

        +--notificationwidget

        |

        +--messageswidget

        |

        +--otherwidget

        |

        +-- ...

      



Thanks

-John

Before you do this, you ought to search for projects that have made Yii widgets for AdminLTE - when I was contemplating using this, I found at least two projects. :)

Don’t bet on it, but if I can find them, I’ll post here - otherwise use Github search and/or Packagist / YiiGist search.

I have done a lot of searching, but sadly, everything I have come up with is either installing as a simple theme, or providing simple widgets for the content area.

While useful, not quite what I am looking for… :(

Until recently, I had this line in my composer.json:


"dmstr/yii2-adminlte-asset": "2.*",

Did you look at that?

I found that to be quite fully featured.

That is what I am using to install the layout. The problem is that it is ONLY the layout. No sample widgets for actually USING features of the layout.

I want to use some of the adminLTE "widgets" in the header bar.

Right now, I am doing stuff like making the display of the username work, then the next thing is the messages.

-John

This was one the resources that I looked at: https://github.com/Insolita/yii2-adminlte-widgets

yea, those are content area widgets.

Not what I am looking for.

Know anything about grouping YII widgets?

-John