有替代解决方案,您可以在 ckeditor 中添加数据而无需编辑实例的值。
例如
在视图中的脚本部分:
<script>
$(function(){
$("#editBasic").click(function(){
url = "<?=$this->webroot?>derivedItineraries/getDetail/<?=$derived_itinerary_id?>";
var div = '#basic_detail';
var data = {id: 1};
callajax(url, data, $(div));
return false;
});
});
</script>
在 Ajax 调用函数中:
function callajax2(url, data, divname){
$.ajax({
type : 'POST',
url : url,
dataType : 'text',
data: data,
success: function(data) {
divname.text('');
divname.append(data);
divname.show(500);
if (data.error === true)
divname.show(500);
}
});
return false;
}
在控制器页面中:
public function getDetail($id = null) {
$this->request->onlyAllow('ajax');
$this->viewClass = 'Json';
$this->loadModel('Destination');
$this->DerivedItinerary->recursive = -1;
$derivedItineraries = $this->DerivedItinerary->findById($id);
$destination_covered = $this->destination_covered($id);
$destinations = $this->Destination->find('list');
$arrData=array(
'itinerary'=>$derivedItineraries,
'destination_covered' => $destination_covered,
'destinations' => $destinations
);
$this->set('data', $arrData);
$this->render('derived_basic', 'ajax');
}
视图中应该有文件,名为“ControllerName”/json/derived_basic.ctp
“derived_itineraries/json/derived_basic.ctp”中的文件内容:
<?php
echo $this->Html->script('/ckeditor/ckeditor', false);
echo $this->Form->create();
echo $this->Form->input('inclusion', array('type'=>'textarea', 'class'=>'ckeditor', 'required'=>'true', 'div'=>'required', 'style'=>'width:200px;', 'value'=> "Test data"))." </td></tr>";
echo $this->Form->end();
?>
试试看。