2

ブラウザの戻るボタンを機能させ、ユーザーが見たものをブックマークできるようにする必要があると感じています。

私はZendルートでは多目的ではありませんが、今のところそれを変更することはできません。

これは私が使用しているajax実装アプローチです:

class TestController extends Zend_Controller_Action {

public function init()
{
    /* Initialize action controller here */
    if ($this->getRequest()->isXMLHttpRequest()) {
        $this->_helper->layout()->setLayout('blank');
        $logger = $this->getInvokeArg('bootstrap')->getResource('Log');
        $logger->debug('AJAX Call');
    }
}


public function indexAction()
{
    // render the default page
}

public function somethingelseAction()
{
    // do something else render something.
}

}

最初のビューをターゲットdivといくつかのリンクでレンダリングします...これが私のindex.phtmlです:

<h1>Tests...</h1>
        <a class="ajaxloader"
            href="<?php echo $this->url(array('controller'=> 'test', 'action' => 'speed'), null, true);?>">Speed</a>
        <a class="ajaxloader"
            href="<?php echo $this->url(array('controller'=> 'test', 'action' => 'somethingelse'), null, true);?>">Something Else</a>
        <div id="testresults">
        <h1>Default stuff to show.</h1>
        </div>

これらの「ajaxloader」リンクにアタッチし、結果を「testresults」divにターゲティングするjQueryコード。

$(function() {
$('.ajaxloader').click(function(event) {
    var target = $(this).attr('href');
    window.location.hash = target;
    $('#testresults').fadeOut('slow', function() {
        // complete fadeout, load new content while it's hiding!
        $.ajax( {
            url : target,
            success : function(data) {
                $('#testresults').html(data);
                $('#testresults').fadeIn();
            }
        });
    });
    return false;
})
});

ここでディープリンクを実装するにはどうすればよいですか?

どうもありがとう、MEM

PS-この実装の良い功績はDarrylE.Clarkeにあります。私は悪いものを取ることができます。

4

1 に答える 1

1

For the deep linking: I had to do the same thing (our code looks almost identical!) and after a while found jQuery Address. There is a problem with IE, though. One of the functions causes it to stop working. As far as I can tell, I'm not using that feature so I've just got it to return instead of doing whatever it is doing. In the current version (1.3.1) it is the function at line 77 (_search = function(el)). Like I said, I just placed a return at the top of the function and it all works nicely now.

As for routes... The documentation should be your first port of call. What I do for routes, is in my bootstrap file, create an _init function and do something like:

$this->bootstrap('frontController');
/* @var $frontcontroller Zend_Controller_Front */
$frontcontroller = $this->getResource('frontController');
$router = $frontcontroller->getRouter();
$router->addRoute(
    'page',
    new Zend_Controller_Router_Route_Regex('(.*)\.html',
        array('controller' => 'index',
        'action' => 'page',
            'module' => 'default'),
            array('page' => 1),
        '%s.html'
    )
);

But put together your own routes to suit your needs (for example you probably don't want to use regex routes).

于 2010-12-03T18:09:44.170 に答える