livecms/transports

Live CMS Transports

v0.0.2 2018-07-31 14:54 UTC

This package is not auto-updated.

Last update: 2024-09-15 05:44:36 UTC


README

这个想法是如何将你的代码(HTML和JavaScript)从你的业务逻辑(模型 - 控制器)传输到视图。

就像一个全局变量,你可以在代码的任何地方设置和访问它。

目前我们提供HTMLTransport和JavascriptTransport。对于HTML传输,你可以在每次将其代码(插入)设置时给它命名,就像变量一样。对于JavaScript,你不能插入相同的脚本,只是为了确保你不会重复你的JavaScript代码。

如何使用

通过composer安装

    composer require livecms/transports

HTML

require vendor/autoload.php;

$htmlTransport = new LiveCMS\Transport\HtmlTransport;

// Set new transport with name 'form'
$html = '<div class="input"><input type="text" name="name" /></div>';
$htmlTransport->set($html, 'form');

// Set new transport with name 'message'
$html = '<div class="message">Hello, Admin</div>';
$htmlTransport->set($html, 'message');

// Append code to 'form'
$html = '<div class="input"><input type="email" name="email" /></div>';
$htmlTransport->append($html, 'form');

// Show content of 'form'
echo $htmlTransport->get('form');

/**
Result :
<div class="input"><input type="text" name="name" /></div>
<div class="input"><input type="email" name="email" /></div>
*/

// Delete content of 'form'
$htmlTransport->flush('form');
echo $htmlTransport->get('form');

/**
Result :
*/

// Use method pull() to get content and delete it.
echo $htmlTransport->pull('form');

// Delete all content
$htmlTransport->flushAll();
echo $htmlTransport->get('message');

/**
Result :
*/

JavaScript

require vendor/autoload.php;

$jsTransport = new LiveCMS\Transport\JavascriptTransport;

// Set new javascript code
$js = <<<JS
    $(':input').first().addClass('focus');
JS;
$jsTransport->set($js);

// Adding another javascript code
$js = <<<JS
    $('.message').text('Hi, bro. Whats up?');
JS;
$jsTransport->append($js);

// Adding another javascript code that same with previous, the code will not be saved.
$js = <<<JS
    $(':input').first().addClass('focus');
JS;
$jsTransport->append($js);

// Show content
echo $jsTransport->get();

/**
Result :
    $(':input').first().addClass('focus');
    $('.message').text('Hi, bro. Whats up?');
*/

// Delete content
$jsTransport->flush();
echo $jsTransport->get();

/**
Result :
*/

许可证

MIT

贡献

从仓库Fork并提交Pull Request

问题和讨论

请创建新的问题或查看已关闭的问题。