iekadou/php_pjaxr

PHP的PJAXR实现

v0.1.2 2015-04-03 10:09 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:43:43 UTC


README

如何安装php-pjaxr?

安装php-pjaxr只需要两个步骤

  1. 将php-pjaxr添加到您的composer.json中

    {
        "require": {
            "iekadou/php_pjaxr": ">=0.1.1",
        }
    }
  2. 在您的视图或模板渲染之前设置当前的Pjaxr命名空间

    use Iekadou\Pjaxr\Pjaxr as Pjaxr;
    ...
    Pjaxr::set_current_namespace('Pjaxr.Home');

如何使用php-pjaxr?

这个例子看起来有很多冗余,实际上只是if-else标签让它变得如此庞大。

// View:
if (!Pjaxr::matches('Pjaxr')) {
    // Do everything you need only for the whole site.
}
if (!Pjaxr::matches('Pjaxr.Home')) {
    // Do everything you need to handle the home page.
}

// Head-Template:
if (!Pjaxr::matches('Pjaxr')) {
    <html>
    <head>
    // Scripts and Stylesheets could be loaded here, no need to reload them when changing the page
    <script...
    <link...
<?php } else { ?>
    <pjaxr-head>
<?php }
...
if (!Pjaxr::matches('Pjaxr')) {
    </head>
<?php } else { ?>
    </pjaxr-head>
<?php }

// Body-Template:
if (!Pjaxr::matches('Pjaxr')) {
    <body>
        <header>...</header>
        <div id="site">
            ...
            <div id="page">
<?php } else { ?>
    <pjaxr-body>
<?php }

// Render everything you need in the page container.

if (!Pjaxr::matches('Pjaxr')) { ?>
            </div>
            ...//site content could still be here
            <footer></footer>
        </div>
    </body>
<?php } else { ?>
    </pjaxr-body>
<?php } ?>

如果您觉得这个例子太复杂,可以尝试结合使用twigtwig-pjaxr进行模板设计。

您需要什么来使用php-pjaxr?

  1. PHP >= 5.3.29
  2. jquery-pjaxr

使用php-pjaxr的项目

  1. pjaxr.io

如果您正在使用twig-pjaxr,请与我联系,并告诉我您在哪些项目中使用了它。谢谢!

祝您快乐地加速您的PHP项目!

获取更多信息,请阅读php-pjaxr on iekadou.com