0

How can I have multiple actions in my layout from different controllers/modules?

I tried this:

<div id="login"><?php $x=new User_LoginController; $x->LoginAction() ?>

<div id="news"><?php $x=new Site_NewsController; $x->ShowAction() ?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Jeremy
  • 57
  • 1
  • 8
  • This is not a good idea. Presumably your login action shows a login form? So you should just output this form (possibly via. a helper) in your layout. – Tim Fountain Apr 11 '13 at 18:13
  • In every view i have ajax code and next is form. I need on site: News, Login/Chat, Last comments, Messagess. I haven't another idea.. – Jeremy Apr 11 '13 at 19:02

2 Answers2

0

I didn't get what exactly you want?

What I guessed is may be you want to call this function(action) from layout to show what is

returning from there into layout......

Anuj Srivastava
  • 144
  • 1
  • 12
  • I need rendering action - controller - module in layout. When I trying that code, i have: Fatal error: Class 'User_LoginController' not found. And i don't have idea, how i can get view/action from different controller in different module. Sorry for my english. – Jeremy Apr 11 '13 at 17:36
  • This may help...... For rendering we often use anchor tag like this... – Anuj Srivastava Apr 11 '13 at 17:51
  • I need 4 modules on one site.. News, login/chat, etc. No links. – Jeremy Apr 11 '13 at 18:54
0

You'll want to implement view helpers, specifically the placeholder() view helper.

For example to render a login form in any or all pages of your application, we start with a placholder for the form in our layout or view script:

<!--layout.phtml-->
<div>
    <?php echo $this->layout()->login . "\n"?>
</div>

I use an action helper to prepare the form for display:

<?php

/**
 * Prepares login form for display
 */
class My_Controller_Action_Helper_Login extends Zend_Controller_Action_Helper_Abstract
{

    /**
     * @return \Application_Form_Login
     */
    public function direct()
    {
        $form = new Application_Form_Login();
        //this is the url of the action this form will default too
        $form->setAction('/index/login');

        return $form;
    }
}

now from any controller or front controller plugin the placeholder can be setup:

public function preDispatch()
    {
        $this->_helper->layout()->login = $this->_helper->login();
    }

now the login form will display in any action from this controller that uses layout.phtml as it's layout. I'll let you discover plugins yourself.

Using helpers with placeholders would usually be the prefered way to accomplish what you want. However if you absolutely must display an action inside of anothers view you can use the Action view helper, just be aware that performance may suffer.

<div id="login">
     <?php echo $this->action('login', 'login', 'user'); ?>
</div>
RockyFord
  • 8,529
  • 1
  • 15
  • 21