On my controller I have the following Action:
public function indexAction()
{
$teamDao = new TeamsDao();
return $teamDao->showName(3);
}
So, I'm returning this team name, and my question is, how can I display this team name on the view ?
Thanks a lot,
MEM
Put this in your controller:
$this->view->teamName = $teamDoa->showName(3);
And this in your view
<?php echo $this->teamName?>
Related
I want to get html content in controller .
for this
public function posteemailAction(){
$view=$this->render("auth-acl/email/_getemail.phtml");
print_r($view);die;
}
Can anyone help for getting content of html in controller.
Thanks
Try this:
public function ajaxAction() {
// Turns off the layout and the view
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
// Creates a new instance of Zend_View
$html = new Zend_View();
// Set a script path for above view
$html->setScriptPath(APPLICATION_PATH . '/views/scripts/your_custom_path/');
// Assinging some data to the view
$html->assign('myVar', $someValue);
// Renders the view to specified variable
$responseContent = $html->render('mycontent.phtml');
echo $responseContent;
}
I am using zend framwork
in my controller i have set string to display in view like
Controller
$this->view->foo = 'sample string or content';
main view
echo $this->foo;
this is working fine show me string sample string or contentbut when i call other view inside this main view its not give any output
i am caaling something like this view inside view.
<?=$this->myform;?>
in myform.phtml
echo $this->foo;
this is not given any output...
Please help me what i am going worng...
thanks
Use Partial Helper like this:
In view:
<?php echo $this->partial('myform.phtml', array('foo' => $this->foo)); ?>
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.
Ive done some search but no success.. i am trying to figure out how to define others layout() parts such layout()->content variable.. i would love to get int layout()->navigation (a custom one) which display the navigation..
Any ideas ?
Thanks.
Not sure if this is what you want, but you can create additional 'parts' of layout simply by assigning a value to your new part. ZF will take care of the rest. For example, in a bootstrap.php you could do:
public function _initNewLayoutPart() {
$view = $this->bootstrap('view')->getResource('view');
$view->layout()->newpart = 'some new part';
}
Then in your layout.phtml you could just echo the new part:
<?php echo $this->layout()->newpart; ?>
It is possible by just creating a new variable in layout, you can define it in your controller (preferably in init or postDispatch). Just like this:
public function init()
{
$this->view->layout()->motd = '<b>Message of the day.</b>';
}
Then in your actual view where you want to see the message, all you have to do is:
<?php echo $this->layout()->motd; ?>
If you want something fancier, such as rendering a whole page or sidebar, try the following:
public function init()
{
$this->view->layout()->sidebar = $this->view->action('render', 'sidebar');
}
With render being the action (including render.phtml) and sidebar being the controller.
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;