Jump to content

Organizing components in subfolders


Ivan Gretsky
 Share

Recommended Posts

Good day, fellow Wireframe users!

@Zeka once asked about how to organize large number of components in subfolders of components folder. Since then @teppointroduced view namespaces (for partials ATM), which probably could be extended to support components.

We have found another way to use components in subfolders - via the usage of php namespaces. In @Zeka's case with  the Blocks subdolder it would work like this:

<?php

// In [wireframeRoot]/components/Blocks/BlockText.php
// Note the namespace

namespace Wireframe\Component\Blocks;

class BlockText extends \Wireframe\Component {

...

and

<?php

// In the view file

<?= Wireframe::component('Blocks\BlockText', [...]); ?>

I guess this is possible due to PSR-4 compliance of the autoloader used. Or maybe @teppohas added something since then.

Do you see this as a valid usage? Do you see any drawbаcks?

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Hey @Ivan Gretsky,

I don't see anything wrong with your approach. This is not something I had specifically planned for, but as you've noted above, it works thanks to the autoloader setup ?

Only "issue" — and it's not much of an issue to be honest — would be that technically /components/Blocks/ should be the "view path" for a component called "Blocks". I can't really think of any real world situation where this would cause problems, though.

The approach Zeka took in earlier posts effectively created a whole new type of components, in some ways more strictly separated from the built-in component structure. I'd say that it's largely a matter of preference.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...