Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-24-2007, 01:52 PM
Junior Member
 
Join Date: May 2007
Posts: 25
Default How to call an action method from a controller?

I'de like to be able to call an action method from some controller without redirecting.
PHP Code:
class FooController extends Zend_Controller_Action
{
    function 
indexAction ()
    {
        echo 
"before call...";
        
$this->_callControllerMethod ("bar""index");
        echo 
"after call...";
    }
}
class 
BarController extends Zend_Controller_Action
{
    function 
indexAction ()
    {
         do 
my logic here and return the control flow to FooController::indexAction 
    
}

Am I missing something? How is this done?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-24-2007, 11:45 PM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

ZF does not provide a way to do that other than _forward() because action should be a complete unit of page and not handle the layout.

You could wrap whatever you extra call into a separate class.
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-31-2007, 10:35 AM
Junior Member
 
Join Date: May 2007
Posts: 25
Default

I do not handle layout this way. Only get data from said controller. I have an editor component and I get content in such a way. Atm I have a plugin for that. but code is messy and I hoped there was a more elegant solution.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-02-2007, 07:52 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

You could create an instance of the BarController
Code:
class FooController extends Zend_Controller_Action 
{ 
    function indexAction () 
    { 
        echo "before call..."; 
        require_once('/path/to/barController.php');
                $barController = new BarController();
                $barReturn = $barController->index(); 
        echo "after call..."; 
    } 
} 
class BarController extends Zend_Controller_Action 
{ 
    function indexAction () 
    { 
         do my logic here and return the control flow to FooController::indexAction  
    } 
}



It's ugly, but it should work. Something along those lines anyway...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:48 PM.