我有一个工作正常的自定义动作助手。 如果用户没有登录,它会生成一个动态登录框,如果他是,它正在生成一个菜单。如何将视图作为对象加入动作助手
但是在这里我有一个问题。 我想从一个叫做user_menu.phtml的小视图中生成该菜单
如何将该视图放入我的视图帮助器中,并将其分配给对象?
好了,一些更新,遗憾的是愚蠢的,actualy我有动作助手:
对不起,如果我是不够具体而写我最初的问题。
所以我有一个动作助手在:library/Hlp/Action/Helper 如果用户没有在旅馆里闲逛,那么这个帮助器就会呈现一个表单。
这里是我的助手方法,做这项工作:
public function preDispatch()
{
$view = $this->getView();
$identity = Zend_Auth::getInstance()->getIdentity();
$session = new Zend_Session_Namespace('users_session');
$user_id = $session->idd;
if(!empty($identity)) {
$userModel = new Application_Model_Vartotojai();
$user_email = $userModel->geUserRowBy('id', $user_id);
$user_email = $user_email['email'];
$view->login_meniu = $identity.' -
[id:'.$user_id.']<br />['.$user_email.'] <br/>
<a href="/authentication/logout">Log OUt</a>';
//here I would like to read view file to an object or some other variable
//if posible to an object si I would be able to inject some values
} else {
$form = new Application_Form_LoginForm();
$view->login_meniu = $form;
$view->register_link = '<br /><a href="https://stackoverflow.com/users/register">Register</a>';
//here I would like to read view file to an object or some other variable
//if posible to an object si I would be able to inject some values
}
Additionaly这种形式我想添加一些链接或其他HTML内容,这将BR存储在一个视图文件。
谢谢Fabio,我认为您的回答接近真相,但我仍然无法正常工作。所以我必须初始化$ view_obj = new Zend_View_Helper_Abstract();然后如何指定我想使用的视图文件? – madcatzx
@madcatzx你应该在你的问题中发布你的当前代码来澄清你的需求。你已经有看法帮手了,是吗?所以在你的类中扩展'Zend_View_Helper_Abstract',你就没事了。我发布了一些代码,也许你可以看看它吗? – Fabio
@madcatzx我已经更新了我的答案以适应您的新请求。 – Fabio