Way to define others layout() parts such layout()->content? - zend-framework

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.

Related

Views from the module won't display (CodeIgniter HMVC)

I'm actually working in an admin panel, and I want to manage all my sliders inside it,
so I created all the functions etc...
In the view file where I want to call the view from the module by running
<?php
echo Modules::run('sliders/_slider_display);
?>
But, The the sliders won't display, I will show you how I did it.
function _slider_display() {
$current_url = current_url();
$query_ads = $this->get_where_custom('target_url', $current_url);
$num_rows_ads = $query_ads->num_rows();
if($num_rows_ads>0){
$this->load->module('slides');
foreach($query_ads->result() as $row)
{
$parent_id= $row->id;
}
$data['query_slides']= $this->slides->get_where_custom('parent_id', $parent_id);
$this->load->view('sliders', $data);
}
}
as I mentioned, I tried to call the view in the homepage, but did not worked, I don't know what is the problem.
Thank you !

Magento2 custom price render on product page

How to format the product view page price differently from the one from category page ( and possible others ) ?
If I change in my child theme the:
app/design/frontend/VENDOR/my_theme/Magento_Catalog/templates/product/price/final_price.phtml
The price is being changed on both pages (category and product);
I have tried several approaches but it seems that this price rendering mechanism is complicated as hell in Magento2.
Thanks!
<?php
try {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get(‘Magento\Framework\App\Action\Context’)->getRequest();
$currentPageXML = $request->getFullActionName();
echo $currentPageXML; //catalog_product_view is product detail page controller action
} catch (Exception $e) {}
?>
The above code will help you get the current area of the environment being accessed, and then you can apply a logic
if ($currentPageXML=="catalog_product_view") {
// render my custom need
} else {
// keep the actual code intact.
}
You are facing a problem because same phtml file is being used by both the catalog and product page, so a change in this file will be reflected everywhere.
I hope this will help you.

pass the variable to child view in zend

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)); ?>

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;

Zend Framework Action Helper Problem

I'm a relative noob when it comes to Zend Framework, however I've got a form that I need to use if a couple of views so I thought I might use a Action Helper to instantiate the form set a few attributes and pass it to the relevant view. I've created the Action Helper and can call it from within the relevant controller's action, however when I try to pass the form to the action's view nothing gets rendered, ie:
$form = new Application_Form_Colour;
if($this->_request->isPost() && $form->isValid($this->_request->getPost()))
{
$model = new Application_Model_Colour();
$model->changeColour($form->getValues());
$form->reset();
}
else
{
$form->newColour->setAttrib('disabled', 'disabled');
}
$this->view->form = $form;
Is there something I am doing wrong or have I got the wrong idea of what an Action Helper can be used for? Maybe its not an Action helper that I need to use?
It turned out I was just being stupid! Instead of
$this->view->form = $form;
at the end of the Action Helper I should have done:
return $form;
Then in my controller:
$this->view->form = $this->_helper->myActionHelper->myActionHelperMethod();
Silly me...