我有一個工作正常的自定義動作助手。 如果用戶沒有登錄,它會生成一個動態登錄框,如果他是,它正在生成一個菜單。如何將視圖作爲對象加入動作助手
但是在這裏我有一個問題。 我想從一個叫做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