ZendX jQuery (Am I missing something?)

For programming and general questions on Zend Framework

ZendX jQuery (Am I missing something?)

Postby panosru on Mon Aug 10, 2009 3:04 pm

Hello, I followed this example but it seems it does not work for me.

On ModuleSwicher.php, a plugin for managing modules, I have the following source:

Code: Select all
<?php
class App_Controller_Plugin_Admin_ModuleSwitcher extends Zend_Controller_Plugin_Abstract
{
    protected $_view = null;
    public function routeShutdown (Zend_Controller_Request_Abstract $request)
    {
        $moduleName = $request->getModuleName();

        Zend_Layout::startMvc();
        $layout = Zend_Layout::getMvcInstance();
        $layout->setLayoutPath('../../public/admin/layouts/scripts')->setLayout($moduleName);

        $view = new Zend_View();
        $view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');

        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $viewRenderer->setView($view);
        $viewRenderer->init();
        Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);

        return $request;
    }
}


And on the default.phtml layout I have this:

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
// Add jQuery
$this->jQuery()->enable();
echo $this->jQuery();
?>
</head>

<body>
<?php echo $this->ajaxLink("Show me something", "/", array('update' => '#foobar')); ?>


<div id="foobar" style="width: 600px; height: 200px; border: 1px solid #000"></div>
</body>
</html>


The generated html source is this:

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script></head>

<body>
<a href="#" class="ajaxLink1">Show me something</a>

<div id="foobar" style="width: 600px; height: 200px; border: 1px solid #000"></div>
</body>
</html>


As you can see there isn't any jQuery code in the page, only the script link to the jQuery code (which I don't know how to load a local jQuery file).

PS: on documentation it says for jQuery UI you have to write $this->jQuery()->enableUi(); but this produces a fatal error Fatal error: Call to undefined method ZendX_JQuery_View_Helper_JQuery_Container::enableUi() in /usr/local/zend/apache2/htdocs/web_projects/Platform/public/admin/layouts/scripts/default.phtml on line 35 instead of ->enableUi() I wrote ->uiEnable() and it worked.

EDIT:
I changed $this->jQuery->uiEnable(); to

Code: Select all
echo $this->jQuery()
    ->addStylesheet('/js/jQuery/UI/themes/cupertino/jquery-ui-1.7.2.custom.css')
    ->setLocalPath('/js/jQuery/jquery-1.3.2.min.js')
    ->setUiLocalPath('/js/jQuery/UI/jquery-ui-1.7.2.custom.min.js');


But still not working...

EDIT2:
I changed it to:
Code: Select all
$this->jQuery()
    ->addStylesheet('/admin/js/jQuery/UI/themes/cupertino/jquery-ui-1.7.2.custom.css')
    ->setLocalPath('/admin/js/jQuery/jquery-1.3.2.min.js')
    ->setUiLocalPath('/admin/js/jQuery/UI/jquery-ui-1.7.2.custom.min.js');

$this->jQuery()->uiEnable();
echo $this->jQuery();
and now my output source is:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>index / index / Administration Panel</title><link rel="stylesheet" href="/admin/js/jQuery/UI/themes/cupertino/jquery-ui-1.7.2.custom.css" type="text/css" media="screen" />

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

</head>

<body>
<a href="#" class="ajaxLink1">Show me something</a>

<div id="foobar" style="width: 600px; height: 200px; border: 1px solid #000"></div>

</body>
</html>


but when I'm clicking on the link there isn't any action, also I don't see any generated code that handle this action.
INTERACTIVE WEB SOLUTIONS | Zend PHP 5 Certified Engineer
PHP Development / Zend Framework / jQuery / XHTML / CSS
-----------------------------------------------
Online CV: http://www.panosru.com/
-----------------------------------------------
panosru
 
Posts: 135
Joined: Mon Mar 02, 2009 2:40 pm
Location: Greece

Re: ZendX jQuery (Am I missing something?)

Postby frlyman on Tue Aug 11, 2009 6:12 pm

What I would recommend trying is echoing $this->jQuery(); at the end of the page, right above the closing body tag. This will enable you to add jquery to the placeholder in your layout script.
frlyman
 
Posts: 7
Joined: Tue Aug 11, 2009 4:56 pm

Re: ZendX jQuery (Am I missing something?)

Postby panosru on Mon Aug 17, 2009 1:50 am

By echoing $this->jQuery(); after the body close tag that wouldn't be valid because link and script tags should be in head section.

Anyway I just add anything I need before echo $this->jQuery();
INTERACTIVE WEB SOLUTIONS | Zend PHP 5 Certified Engineer
PHP Development / Zend Framework / jQuery / XHTML / CSS
-----------------------------------------------
Online CV: http://www.panosru.com/
-----------------------------------------------
panosru
 
Posts: 135
Joined: Mon Mar 02, 2009 2:40 pm
Location: Greece

Re: ZendX jQuery (Am I missing something?)

Postby martinph on Mon Aug 17, 2009 5:21 pm

I think frlyman meant before the closing body tag, which is still valid. It is actually good practice to shift all your .js includes to just before the </body> tag. Doing this ensures that the DOM is constructed before the browser starts spawning new threads for the JS includes. Which is invaluable when including externally hosted js files.

http://javascriptant.com/articles/10/qa ... techniques
martinph
 
Posts: 21
Joined: Thu May 28, 2009 1:58 pm

Re: ZendX jQuery (Am I missing something?)

Postby stelu_26 on Mon Oct 11, 2010 7:32 am

If you have a layout file then you put the ".... $this->jQuery(); ....etc .." in this file then work.
I don't know why but work.
stelu_26
 
Posts: 1
Joined: Mon Oct 11, 2010 7:30 am


Return to Zend Framework

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests