2

I have a view helper method which is like this

class Zend_View_Helper_LoginForm extends Zend_View_Helper_Abstract
{
    public function loginForm()
    {
        $script = "<script type='text/javascript'>(function (){ $('#submit').click(function (){alert('hello'); return false;})})</script>";     
        $this->view->headScript()->appendScript($script, $type = 'text/javascript');
        $login = new Application_Form_User();
        return $login;
    }

}

But this is not working. I also tried

$this->view->headScript()->appendFile($this->view->baseUrl('/js/jquery.js'), 'text/javascript');

but this is not working either. If i try this code in layout.phtml then it works.Any Idea?

2
  • It should work. Are you calling <?php echo $this->headScript(); ?> in your layout ? Commented Nov 30, 2010 at 13:39
  • yes i am sure i have called this in my layout.phtml file Commented Dec 3, 2010 at 4:56

2 Answers 2

1

In view file:

<?php $this->headScript()->appendFile('your/sript/file.js') ?>

In your layout:

<?php echo $this->headScript() ?>
Sign up to request clarification or add additional context in comments.

1 Comment

I cannot append this file in view file because this script is for a common plugin that all views share
0

You have to add setView method:

class My_View_Helper_ScriptPath { public $view;

public function setView(Zend_View_Interface $view)
{
    $this->view = $view;
}

public function scriptPath($script)
{
    return $this->view->getScriptPath($script);
}

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.