How to render methodAction of another Controller inside an action - typo3

I'm using extbase, fluid system on typo3 to build a backend module.
I Have a Controller "MainController" action called 'AddBoxes' and I have another Controller called BoxElementsController, and there is an action method called 'popupBoxAction'.
I want to render the output of the BoxElementsController->popupBoxAction in the MainController-AddBoxesAction();
so that I can assign the output to my view variable.
How can i achieve this in Typo3 6.1.
Thanks

Also you can fetch data or output whatever you like from BoxElementsRepository
class MainController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
protected $boxElementsRepository;
public function injectBoxElementsRepository(BoxElementsRepository $boxElementsRepository) {
$this->boxElementsRepository = $boxElementsRepository;
}
public function AddBoxesAction(){
$popupBoxActionOutput = $this->boxElementsRepository->popupBox();
$addBoxesAction = $this->mainRepository->findAll();
$this->view->assignMultiple(array(
'popupBoxActionOutput' => $popupBoxActionOutput,
'addBoxesAction' => $addBoxesAction,
));
}
}

Try to instantiate you controller in you action then call ControllerObject->initializeAction() before calling your desired action.

Related

How to disable view renderer from a controller action helper ?

In a controller, I can call viewRenderer helper like this :
$this->_helper->viewRenderer->setNoRender(true);
How can I call viewRenderer in a controller action helper?
Assume that I have a Controller action helper :
class Zend_Controller_Action_Helper_Ajaxrequest extends Zend_Controller_Action_Helper_Abstract{
public function test(){
//what I should do here
}
}
viewRenderer in your example is actually an action helper, not a view helper.
To call action helpers, use the helper broker:
$helper = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$helper->setNoRender(true);
If you actually want to call view helpers, you need a view instance. You can get one from the controller:
$controller = $this->getActionController();
//call the url view helper
$controller->view->url(...);

Whats the way to use Zend_Acl in View to show/hide parts of view

I am wondering whats the way to use Zend_Acl to show/hide parts of view? I am thinking I will
Create a Controller Plugin that passes the logged in user + acl to view
$this->view->loggedInUser = Zend_Auth::getIdentity();
$this->view->acl = Zend_Registry::get('acl');
Then in view scripts do something like
$this->acl->isAllowed($this->view->loggedInUser, 'resource', 'privilege');
Or is there a better way? Or should I use a View Helper? That returns a boolean whether the logged in user is allowed?
You are using it in the view, so for me ViewHelper is correct place for that - I've done it once that way:
class Zend_View_Helper_HasAccess extends Zend_View_Helper_Abstract
{
private $_acl;
public function hasAccess($role, $controller, $action)
{
if (!$this->_acl) {
$this->_acl = Zend_Controller_Front::getInstance()->getPlugin('Acl');
//In yout case registry, but front controller plugin is better way to implement ACL
}
return $this->_acl->isAllowed($role, $controller, $action);
}
}

Load Zend_Form from a view helper in Zend?

Is it possible to load a Zend_Form from a view helper? I'm using thise form in a login action method. But I also want this form to be visible on the navigation on every page (so without the login action actually being called yet), the post method of the form will send to the login action method.
I'm guessing it should be done with a view helper but I don't see how.
Any ideas?
I tried with this:
my view helper:
class Zend_View_Helper_LoginForm
{
function getLoginForm(){
$form = new Form_LoginForm();
return $form;
}
}
and I call it from my layout like this:
<?php echo $this->form(); ?> but this doesn't work. (I'm able to call the same form through an action method though!)
In this case it gives me this error (which doesn't make sense because my helper is only 9 lines long):
Warning: Missing argument 1 for Zend_View_Helper_Form::form() in C:\xampplite\htdocs\zendpr\library\Zend\View\Helper\Form.php on line 44
Your view helper should extends the Zend_View_Helper_Abstract class and the method of the view helper must have the same name as the class :
class Zend_View_Helper_LoginForm extends Zend_View_Helper_Abstract
{
function loginForm() {
$form = new Form_LoginForm();
return $form;
}
}
and you call it like this in your view script :
echo $this->loginForm();
If you call :
echo $this->form();
You are using the view helper Zend_View_Helper_Form
Have your View_Helper extend Zend_View_Helper_Abstract and override the setView()
class Zend_View_Helper_XX extends Zend_View_Helper_Abstract {
public $view;
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
}
Initialise the form in your controller action and set the form reference
// controller action code
$this->view->form = $form;
Then in the view helper you can reference the form via the view
// view helper code
$this->view->form;
class Zend_View_Helper_LoginForm extents Zend_Form {
function getLoginForm(){
$form = new Form_LoginForm();
return $form;
}
}
OR
$this->view->form=$form;
Both are going to return the form. The view form is more specific for view.
Add this into your phtml view file
echo $this->form();
To answer this question - Remove the Parenthetical
Should be
echo $this->form;

How do i assign a custom helper to each view differently in zend framework

i have a custom helper written which returns the html form as string which extends the Zend_view-hepler_Abstract
Now i have 3 helpers .How do i assign each helper to a different view .
It is something like this in the controller
class abc extends Zend_controller_front{
public action page1Action (){
// I want to use a different Helper
//How do i assign custom1 helper to this view Separately
}
public action page2Action (){
// I want to use a different Helper
//How do i assign custom2 helper to this view Separately
}
public action page3Action (){
// I want to use a different Helper
//How do i assign custom3 helper to this view Separately
}
}
um, should you be inheriting from Zend_Controller_Action not Zend_Controller_Front?
also the word 'action' is not a valid php keyword?
just use the view helper in your view script, so in abc/page1.phtml
print $this->page1Helper()
similarly for page2 and page3
but there may be an easier way... you can just
print $this->form;
and the form will print without the need for a helper?

set/add view from controller action

I'm trying to set a view script to be executed in addition to the currently requested action view script. I want to do this from the controller action itself in a way that this new view script output will be available from the layout $this->layout()->content helper.
I found the setView() method but don't know how to use it from the controller.
Thanks a lot.
If you just want to render some other view script from a controller just:
$this->render('someotherview');
Wich will render someotherview.phtml.
from: http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.viewintegration.render
class MyController extends Zend_Controller_Action{
public function fooAction()
{
// Renders my/foo.phtml
$this->render();
// Renders my/bar.phtml
$this->render('bar');
// Renders baz.phtml
$this->render('baz', null, true);
// Renders my/login.phtml to the 'form' segment of the
// response object
$this->render('login', 'form');
// Renders site.phtml to the 'page' segment of the response
// object; does not use the 'my/' subirectory
$this->render('site', 'page', true);
}
public function bazBatAction()
{
// Renders my/baz-bat.phtml
$this->render();
}
}
Should get you on the right track!
Also
$this->renderScript('path/to/index.phtml');
Works really well.