Question

I'm struggling to build a simple zend framework application that can call jQuery. So, what I'm working under Zend Studio 7.1.1 where I added, in the library folder, the "ZendX" folder. And, I also downloaded the jQuery lightness theme that was added to the "js" public folder.

You'll find the whole structure is like that: http://www.freeimagehosting.net/image.php?b95bca6dab.png So what I did is: 1- Added the following lines into the Bootstrap.php file so that I obtained the following content:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{


}
Zend_Loader::registerAutoload();
$view= new Zend_View();
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
$view->jQuery()->addStylesheet('/js/jquery/css/ui-lightness/jquery-ui-1.7.2.custom.css')
        ->setLocalPath('/js/jquery/js/jquery-1.3.2.min.js')
        ->setUiLocalPath('/js/jquery/js/jquery-ui-1.7.2.custom.min.js');

Then, as I don't use the layouts, I directly added the datepicker in the index.phtml file with the $view->jQuery() and $view->jQuery() even if when I type $view-> the Zend Studio intellisense system doesn't propose the jQuery() function. Anyway, the index.phtml file is:

<style>
    a:link,
    a:visited
    {
        color: #0398CA;
    }

    span#zf-name
    {
        color: #91BE3F;
    }

    div#welcome
    {
        color: #FFFFFF;
        background-image: url(http://framework.zend.com/images/bkg_header.jpg);
        width:  600px;
        height: 400px;
        border: 2px solid #444444;
        overflow: hidden;
        text-align: center;
    }

    div#more-information
    {
        background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif);
        height: 100%;
    }
</style>
<div id="welcome">
    <h1>Welcome to the <span id="zf-name">Zend Framework!</span></h1>

    <h3>This is your project's main page</h3>

<?php echo $this->headScript(); ?>
<?php echo $this->jQuery()->uiEnable();?>
<?php echo $this->jQuery(); ?>
<form id='ok'>
Pick your Date: <?php echo $this->datePicker('dp1', '', array('defaultDate' => date('Y/m/d', time()))); ?>
</form>
    <div id="more-information">
        <p><img src="http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png" /></p>
        <p>
            Helpful Links: <br />
            <a href="http://framework.zend.com/">Zend Framework Website</a> |
            <a href="http://framework.zend.com/manual/en/">Zend Framework Manual</a>
        </p>
    </div>
</div>

But nothing works!

I get the following output:

ttp://www.freeimagehosting.net/uploads/7ed0166140.png

As you can see, the datepicker input text is here, but on click, it shows nothing.

And for the source page (index.phtml):

<style> 
    a:link,
    a:visited
    {
        color: #0398CA;
    }

    span#zf-name
    {
        color: #91BE3F;
    }

    div#welcome
    {
        color: #FFFFFF;
        background-image: url(http://framework.zend.com/images/bkg_header.jpg);
        width:  600px;
        height: 400px;
        border: 2px solid #444444;
        overflow: hidden;
        text-align: center;
    }

    div#more-information
    {
        background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif);
        height: 100%;
    }
</style> 
<div id="welcome"> 
    <h1>Welcome to the <span id="zf-name">Zend Framework!</span></h1> 

    <h3>This is your project's main page</h3> 


<link rel="stylesheet" href="../public/js/jquery/css/ui-lightness/jquery-ui-1.7.2.custom.css" type="text/css" media="screen"> 

<script type="text/javascript" src="../public/js/jquery/js/jquery-1.3.2.min.js"></script> 
<script type="text/javascript" src="../public/js/jquery/js/jquery-ui-1.7.2.custom.min.js"></script> 

<form id='ok'> 
Pick your Date: <input type="text" name="dp1" id="dp1" value=""></form> 
    <div id="more-information"> 
        <p><img src="http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png" /></p> 
        <p> 
            Helpful Links: <br /> 
            <a href="http://framework.zend.com/">Zend Framework Website</a> |
            <a href="http://framework.zend.com/manual/en/">Zend Framework Manual</a> 
        </p> 
    </div> 
</div>

I really tried many combinaisons, but no way to figure out it! If also tried to find a video showing exactly, step by step, how to integrate jQuery in Zend.

What's wrong in the code?

If you can help me, I would really appreciate that!

Thanks very much,

regards.

Was it helpful?

Solution

<?php $this->jQuery->enable;?> should be enable() and reside in the controller/bootstrap.


If you'd like to add jQuery to all pages, I would change

$view->jQuery()->addStylesheet('/js/jquery/css/ui-lightness/jquery-ui-1.7.2.custom.css')
    ->setLocalPath('/js/jquery/js/jquery-1.3.2.min.js')
    ->setUiLocalPath('/js/jquery/js/jquery-ui-1.7.2.custom.min.js');

to

$view->jQuery()->addStylesheet('/js/jquery/css/ui-lightness/jquery-ui-1.7.2.custom.css')
    ->setLocalPath('/js/jquery/js/jquery-1.3.2.min.js')
    ->setUiLocalPath('/js/jquery/js/jquery-ui-1.7.2.custom.min.js')
    ->enable()
    ->enableUi();

, otherwise you don't need to enable it at all, since calling a helper like datePicker() automatically inclues jQuery and jQuery UI on your page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top