我为Concrete5构建了一个自定义块,它使用与之关联的多个模板文件。如果我在最初将块添加到页面时将模板应用于块,一切正常。但是,如果我在块已经设置后尝试更改模板,则会遇到问题。使用新模板保存更改时,我的所有内容都会从数据库中删除;所以当前行中的所有内容都等于null,除了块ID“bID”,bID将更改为下一个增量。
我不知道为什么会这样!我觉得我很久以前遇到过类似的事情,但不记得它是如何解决的。任何建议都会很棒!
我的模板文件只是一个php文件中的标准html,文件顶部有<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
。
我的控制器(我现在怀疑这个问题)看起来像这样:
<?php
namespace Concrete\Package\ThemeCaboodle\Block\GridBlock;
use Concrete\Core\Block\BlockController;
use Database;
use Page;
use Concrete\Core\Editor\LinkAbstractor;
use Core;
use File;
use View;
use BlockType;
class Controller extends BlockController
{
public $defaultBlockClassList = '';
public $defaultEntriesClassList = 'unit-md-4';
protected $btTable = 'btGrid';
protected $btExportTables = array('btGrid', 'btGridEntries');
protected $btInterfaceWidth = "600";
protected $btWrapperClass = 'ccm-ui';
protected $btInterfaceHeight = "550";
protected $btCacheBlockRecord = true;
protected $btExportFileColumns = array('thumbnailFID');
protected $btCacheBlockOutput = true;
protected $btCacheBlockOutputOnPost = true;
protected $btCacheBlockOutputForRegisteredUsers = false;
protected $btIgnorePageThemeGridFrameworkContainer = true;
public function getBlockTypeDescription()
{
return t("Easily add a grid with prebuilt templates to your site using the grid block");
}
public function getBlockTypeName()
{
return t("Grid");
}
public function getFileObject($fID) {
return File::getByID($fID);
}
public function getSearchableContent()
{
$db = Database::get();
$rows = $db->Execute('SELECT * FROM btGridEntries WHERE bID = ?', array($this->bID));
$content = '';
foreach ($rows as $row) {
$content .= $row['title'].' ';
$content .= $row['description'].' ';
}
return $content;
}
public function view()
{
$this->set('entries', $this->getEntries());
$this->set('block', $this->getBlockData());
$this->addHeaderItem('<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"/>');
}
public function add()
{
$this->requireAsset('core/file-manager');
$this->requireAsset('core/sitemap');
$this->requireAsset('redactor');
}
public function edit()
{
$this->requireAsset('core/file-manager');
$this->requireAsset('core/sitemap');
$this->requireAsset('redactor');
$this->set('entries', $this->getEntries());
$this->set('block', $this->getBlockData());
}
public function composer()
{
$this->edit();
}
public function registerViewAssets($outputContent = '')
{
$al = \Concrete\Core\Asset\AssetList::getInstance();
$this->requireAsset('javascript', 'jquery');
}
public function duplicate($newBID)
{
parent::duplicate($newBID);
$db = Database::get();
$rows = $db->Execute('SELECT * FROM btGridEntries WHERE bID = ?', array($this->bID));
while ($row = $rows->FetchRow()) {
$db->execute('INSERT INTO btGridEntries (bID, thumbnailFID, fallbackFID, title, description, classList, buttonText, sortOrder, externalLinkURL, internalLinkCID, fileFID) values(?,?,?,?,?,?,?,?,?,?,?)',
array(
$newBID,
$row['ENTRY_thumbnailFID'],
$row['ENTRY_fallbackFID'],
$row['ENTRY_title'],
$row['ENTRY_description'],
$row['ENTRY_classList'],
$row['ENTRY_buttonText'],
$row['ENTRY_sortOrder'],
$row['ENTRY_externalLinkURL'],
$row['ENTRY_internalLinkCID'],
$row['ENTRY_fileFID']
)
);
}
}
public function delete()
{
$db = Database::get();
$db->delete('btGridEntries', array('bID' => $this->bID));
parent::delete();
}
public function save($args)
{
$db = Database::get();
$db->execute('DELETE from btGridEntries WHERE bID = ?', array($this->bID));
parent::save($args);
if (isset($args['ENTRY_sortOrder'])) {
$count = count($args['ENTRY_sortOrder']);
$i = 0;
while ($i < $count) {
$externalLinkURL = $args['ENTRY_externalLinkURL'][$i];
$internalLinkCID = $args['ENTRY_internalLinkCID'][$i];
$fileFID = $args['ENTRY_fileFID'][$i];
switch (intval($args['ENTRY_linkType'][$i])) {
case 1:
$externalLinkURL = '';
$fileFID = 0;
break;
case 2:
$internalLinkCID = 0;
$fileFID = 0;
break;
case 3:
$externalLinkURL = '';
$internalLinkCID = 0;
break;
default:
$externalLinkURL = '';
$internalLinkCID = 0;
$fileFID = 0;
break;
}
if (isset($args['ENTRY_description'][$i])) {
$args['ENTRY_description'][$i] = LinkAbstractor::translateTo($args['ENTRY_description'][$i]);
}
$db->execute('INSERT INTO btGridEntries (bID, thumbnailFID, fallbackFID, title, description, classList, buttonText, sortOrder, externalLinkURL, internalLinkCID, fileFID) values(?,?,?,?,?,?,?,?,?,?,?)',
array(
$this->bID,
intval($args['ENTRY_thumbnailFID'][$i]),
intval($args['ENTRY_fallbackFID'][$i]),
$args['ENTRY_title'][$i],
$args['ENTRY_description'][$i],
$args['ENTRY_classList'][$i],
$args['ENTRY_buttonText'][$i],
$args['ENTRY_sortOrder'][$i],
$externalLinkURL,
$internalLinkCID,
$fileFID
)
);
++$i;
}
}
}
public function getBlockAssetPath() {
$bt = BlockType::getByHandle('buckets_block');
return Core::make('helper/concrete/urls')->getBlockTypeAssetsURL($bt);
}
public function getBlockData()
{
$db = Database::get();
$row = $db->GetRow('SELECT * FROM btGrid WHERE bID = ?', array($this->bID));
if ($row['bgFID']) {
$row['BG'] = \File::getByID($row['bgFID'])->getVersion()->getRelativePath();
}
return $row;
}
public function getEntries()
{
$v = View::getInstance();
$db = Database::get();
$rows = $db->GetAll('SELECT * FROM btGridEntries WHERE bID = ? ORDER BY sortOrder', array($this->bID));
// in view mode, linkURL takes us to where we need to go whether it's on our site or elsewhere
$entries = array();
foreach ($rows as $row) {
// Generate the URL based on what the linkType is
if ($row['externalLinkURL'] =='' && !$row['fileFID'] && $row['internalLinkCID']) {
$c = Page::getByID($row['internalLinkCID'], 'ACTIVE');
$row['linkURL'] = $c->getCollectionLink();
} elseif ($row['externalLinkURL'] =='' && !$row['internalLinkCID'] && $row['fileFID']) {
$f = File::getByID($row['fileFID']);
$row['linkURL'] = $f ? $f->getVersion()->getRelativePath() : '';
} elseif ($row['externalLinkURL']!='') {
$row['linkURL'] = $row['externalLinkURL'];
} else {
$row['linkURL'] = '';
}
// Thumbnail
$thumbnail = $row['thumbnailFID'] ? File::getByID($row['thumbnailFID'])->getVersion()->getRelativePath() : $v->getThemePath().'/no-image.jpg';
$row['thumbnail'] = $thumbnail;
$fallback = $row['fallbackFID'] ? File::getByID($row['fallbackFID'])->getVersion()->getRelativePath() : $v->getThemePath().'/no-image.jpg';
$row['fallback'] = $fallback;
$row['description'] = LinkAbstractor::translateFrom($row['description']);
$entries[] = $row;
}
return $entries;
}
public function getClassList($string) {
$array = explode(',',$string);
if (count($array) > 0) {
return implode(' ',$array);
}
}
}
我提前为这个漂亮的文件道歉;)我只是想确保你能看到所有可能出现的问题
答案 0 :(得分:0)
我认为你的问题是在复制函数中,一旦你从你的选择中得到了你的结果,你就像在$ row ['ENTRY_thumbnailFID']中那样放置一个ENTRY_前缀,当它真的应该是$ row ['thumbnailFID']根据你的截图