在Yii
中使用Ckeditor
扩展,我只想在数据库、中插入数据
一旦Ckeditor
显示它的精细,但用<p>
标记本身在Db中插入数据。
例如,
<p>Sample</p>
插入Db
但我只想要Sample
,而不是<p>
和<br>
标签等。
您可以为此使用PHP strip_tag,并在控制器中去掉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,
....
};
以下是完整的步骤:
- 下载Ckeditor
- 提取下载的文件,并将ckeditor文件夹放在受保护的文件夹之外。您的文件夹结构应为:
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>