0

I'm developing an php mvc framework and faced a problem to render view in layout, that is serviced by controller. For example, login box is common for all pages of site. Here is my layout:

<?= $this->partial('layouts/header') ?>
<aside class="login-box">
    <?= $this->partial('indexController', 'loginboxAction');
</aside>
<section class="main">
    <?= $this->content() ?>
</section>
<?= $this->partial('layouts/footer') ?>

There is no problem with static or near-static header/footer templates, but user block can chage it's state, and it's behavior can be managed by controller (as indexController did).

How to make such partial method, that can do such magic? It looks like i need force FrontController to render the whole MVC for this controller, don't i? But it will be very inefficient. Or maybe I think wrong, and such block, as user-box, can be just a view, without linking with controller?

I understand, that my question is much abstract and i provided no code, but it is more architecture question, than technical.

4
  • What you have there has nothing to do with MVC. It's just a dumb template. Commented Jul 6, 2014 at 12:15
  • It's not really clear what's the problem. Each controller needs to have sufficient data about what it is doing. One of the things it does is to provide data for views. You need to be able to render different views (or view parts) based on different controller parameters. Commented Jul 6, 2014 at 12:39
  • @Shomz actually, if instead of mimicking Rails you try to implement MVC, controllers do not provide data to the views. Commented Jul 6, 2014 at 15:33
  • @tereško how your example can help me to render view in view's template? Commented Jul 6, 2014 at 21:18

1 Answer 1

1

I can think about different ways to do that :

  1. As you mentionned, call the MVC triad for that component. If you say this is inefficient, maybe you have to refactor the part that dispatches a request (this technique is called HMVC).

  2. Attach somehow a view model/composer to that component, like Laravel's View Composers. Check this out: http://laravel.com/docs/responses#view-composers

  3. Call a view helper from the template. Your View component can register a set of view helpers, and you could call these from any template. Zend Framework provides by default a set of useful view helpers, check it out: http://framework.zend.com/manual/2.3/en/modules/zend.view.helpers.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.