在Ckeditor
中使用Yii
扩展我只想在数据库中插入数据,
一旦Ckeditor
显示其正常但在Db中插入带<p>
标记的数据。
例如,
<p>Sample</p>
在Db中插入
但我只想Sample
而不是<p>
和<br>
标签等。
答案 0 :(得分:0)
您可以使用PHP strip_tags来删除控制器中的html标记(请注意这将删除所有html标记),例如:
public function actionCreate()
{
$model=new MyModel;
if(isset($_POST['MyModel']))
{
$model->attributes=$_POST['MyModel'];
$model->mytext = strip_tags($model->mytext);//strip html tags
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
修改强>
如果要删除显示的默认<p>
,可以执行以下操作:
var config = {
...
enterMode : CKEDITOR.ENTER_BR,
shiftEnterMode: CKEDITOR.ENTER_P,
....
};
以下是完整的步骤:
webapp/ckeditor
在视图中添加代码:
<?php
$js=Yii::app()->getClientScript();
$js->registerScriptFile(Yii::app()->baseUrl.'/ckeditor/ckeditor.js');
$js->registerScriptFile(Yii::app()->baseUrl.'/ckeditor/adapters/jquery.js');
$js->registerScript(
'js2',
'
var config = {
toolbar:
[
["Bold", "Italic","Underline", "-", "NumberedList", "BulletedList", "-" ],
["UIColor"],["TextColor"],["Undo","Redo","Link"],
["JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"],
["NumberedList","BulletedList","FontSize","Font","Preview"]
],
enterMode : CKEDITOR.ENTER_BR,
shiftEnterMode: CKEDITOR.ENTER_P,
height:150,
width:580
};
$("#State_state").ckeditor(config);
',
CClientScript::POS_LOAD
);
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'state-form',
'enableAjaxValidation'=>false,
));
?>
<div class="row">
<?php echo $form->labelEx($model,'state'); ?>
<?php echo $form->textArea($model,'state'); ?>
<?php echo $form->error($model,'state'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div>