How to call viewHelper via OPT - php

I work with Zend Framework 1.12 and Open Power Template.
In ZF I made view helper InfolineData with method getDispayInfoline($lang) (class name Callcenter_View_Helper_InfolineData) and I pass this helper via controller to view.
Controller Code:
$this->view->openHours = $this->view->getHelper('infolineData')->getDispayInfoline($lang);
View Code:
{$openHours}
How can I make similar call using only Open Power Template?

Ok, I find solution
$this->view->getHelper('infolineData')->getDispayInfoline($lang)
is equal to
{u:$view::getHelper('infolineData')::getDispayInfoline($view::language)}

Related

ACL check in the view

Well in ZF1 there was the isAllowed view helper to check the ACL in the view.
But I can't find an equivalent of it for ZF2. The closest I got was the ZF2 navigation view helper, but the problem with that is that it requires a AbstractPage. I just want to throw a resource/privilege to it, example:
$this->allowed('resource', 'privilege');
Is there not such a view helper, or am I looking at this all the wrong way?
Well I couldn't find any view helper, neither got any response so I wrote my own view helper.
isAllowed view helper code

Zend Framework: How to register and call plugin in bootstrap file

1- How can I register and call my plugin in bootstrap file?
2- Is it a better way to use boostrap file intead of application.ini file for registering and calling my plugins ?
Note: Iam using custom path ('Mylib/Controller/Plugin') for storing my plugins.
Actually I want to convert following 'application.ini' entries
autoloaderNamespaces[] = "Mylib_"
resources.frontController.plugins.CheckHasAccess = "Mylib_Controller_Plugin_CheckHasAccess"
into bootstrap _initPlugin function.
Can some one guide me in this regards with some sample code.
Thanks in advance
1 - You would need first to load your plugin class (via Zend_Loader or require_once)
then create your plugin yourself:
$plugin = new MyPlugin();
then you can call any public method of your plugin you want and at the end you can register it within front controller:
Zend_Controller_Front::getInstance()->registerPlugin($plugin);
2 - if your plugins need to be somehow configured before they can be used by framework - then you can create and configure them yourself (as described above). If they don't need any special actions - then you can let them to be created by Framework automatically.

Use view helpers in controllers in Zend Framework

I have a controller that is called with AJAX (sends JSON data), so I don't use a view.
I need to use a personnal view helper to format my data, but in my controller.
Is that possible ?
Or maybe I am doing it wrong (maybe I should have a view, but how with JSON) ?
You can access any ViewHelper from the Controller by
$this->view->helpername(/*params*/);
// or
$helper = $this->view->getHelper('helpername');
// or
$broker = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$broker->getView()->helpername(/*params*/);
See Zend: How to use a custom function from a view helper in the controller?
However, you might be right that you are doing it wrong (funny pic btw), but I cannot really tell from your question. Please refine it as to why you need to call the view helper and what it is supposed to format.
Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
Just be sure that the returned view is the view you want. Because down the line, the view may get overwritten and on the controller you have a spank new view.
And all those values you setup on the view on the action helper and the like... before the controller is kicked in? All gone with the wind!
So test before assuming that if you get a view resource. it is really the same view resource you expect, and that all your vars are still there.
You may be surprised as i was!
You can create an instance of a Helper .. this will work in Controllers, Models and everywhere you need the Helper.
eg.
// create Instance
$serverUrl_helper = new Zend_View_Helper_ServerUrl();
// get the ServerUrl
$serverUrl = $serverUrl_helper->serverUrl();
Another approach is to use the ContextSwitch or AjaxContext action-helpers. This allows you to use a view-script from which you can then call your view-helper in the standard manner.
Just use action helpers, many of view helpers are available as action helpers too.
Or directly by using Zend_Date or sprintf.

Determine Current Controller in Use for Kohana

What is the best way to determine which Controller class a Kohana application is presently using?
Examples:
http://sitesite.com/ - _defaultControllerName_
http://somesite.com/frontpage/articles - "frontpage"
http://somesite.com/contact/ - "contact"
The following applies to Kohana 2 instances...
You can do this by using the Router library. By default, this library is located in /system/libraries/Router.php - go ahead and copy it into /application/libraries as is the standard practice for all libraries being used.
Now, from within your application you can get the controller value from the static Router class:
print Router::$controller; // outputs current Controller
Documentation
For Kohana 3.x, you need to get the current controller from the Request object:
echo Request::$current->controller();

Symfony: Is it possible to setTemplate for components?

There’s no setTemplate() for components! I know but maybe there is another way to do it ?
(The question seems to be about a php framework: http://www.symfony-project.org/)
There is no setTemplate method on sfComponents. You essentially have 3 options:
Name your component the same as the partial you'd like the component to render. This may not be possible if you have multiple components you'd like to share the same template.
Create a partial with the same name of your component and include the partial there. That is, if you had a component with an executeFoo() method that you wanted to render the _bar.php template, simply call include_partial('bar', $vars) inside of _foo.php.
Load the PartialHelper and render the partial manually inside of the components execute method and have the component return sfView::NONE.
Components don't handle templates, you can only use partials. If you need to return a specific partial from inside your components class you can do something like this:
return get_partial('module/action', array('paramName' => $paramValue));
Have a look into the symfony book, chapter 7 view layer
To get around this, i'm doing:
echo get_component('module', 'action', $this->getVarHolder()->getAll());
return sfView::NONE;
This worked for me:
$this->setVar('template', 'templateName');
Obviously the template have to be in the exactly same module.

Categories