I have a log in form that appears at the top of the page. I should appear only if the user is not logged in in all pages. Where should i declare the class that generates login form so that i can use it in my layout. i tried on my bootstrap class
protected function _initView(){
$this->bootstrap('view');
$view = $this->getResource('view');
$view->headLink()->appendStylesheet($view->baseUrl('/css/default.css'));
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity()) {
$login = new Application_Form_User();
$view->login = $login;
}
}
didn't work either. I Also triedprotected function _initView(){
$view = new Zend_View();
$view->headLink()->appendStylesheet('http://localhost/backend/public/css/default.css');
$auth = Zend_Auth::getInstance();
开发者_运维知识库 if(!$auth->hasIdentity()) {
$login = new Application_Form_User();
$view->login = $login;
}}
Create a view helper like so:
class Application_View_Helper_LoginForm
{
public function loginForm()
{
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity())
{
$login = new Application_Form_User();
return $login;
}
}
}
You must also register the view helper path in your Bootstrap. Parameter one is the path and parameter two is the prefix of the class name.
protected function _initViewHelpers()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addHelperPath(APPLICATION_PATH . '/views/helpers/', 'Application_View_Helper');
}
Then to display the form, add the following code in your layout:
<?php echo $this->loginForm(); ?>
Use a view helper to display the form / "logged in" text.
You can use a specific controller action to handle the form or use a controller action helper to handle the login form submission on any page.
Use a front controller plugin for that. See http://devzone.zend.com/article/3372
精彩评论