use yii 1.1.7 implement xheditor

download jquery.js and xheditor.tar.gz

extra to Root/assets

structure:

webROOT/

  assets/


     jquery/jquery-1.5.1.min.js


     xheditor-1.1.5/


         xheditor-en.min.js


         ....

in controller:




	public function actionCreate()

	{

		$model=new News;

		$clientScript = Yii::app()->clientScript;

		$clientScript->packages = array(

		  'jquery'=>array(

		    'basePath'=>'application.assets.jquery',

		    'baseUrl'=>'/assets/jquery',

		    'js'=>array('jquery-1.5.1.min.js'),

		    //'css'=>array(list of css files relative to basePath/baseUrl),

		  ),

		  'xheditor'=>array(

		    'basePath'=>'application.assets.xheditor-1.1.5',

		    'baseUrl'=>'/assets/xheditor-1.1.5',

		    'js'=>array('xheditor-en.min.js'),

		    //'css'=>array(list of css files relative to basePath/baseUrl),

		  ),

		);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['News']))

		{

			$model->attributes=$_POST['News'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		

		$this->render('create',array(

			'model'=>$model,

		));

	}



in view:




<?php

$jquery = Yii::app()->clientScript->registerPackage('jquery');

$xheditor = Yii::app()->clientScript->registerPackage('xheditor');


?>

<script type="text/javascript">

$(function(){

	$('#News_content').xheditor({width:600,height:200,upBtnText:'upload now',upMultiple:5,upLinkUrl:'upload.php',upLinkExt:'zip,rar,txt',upImgUrl:'upload.php',upImgExt:'jpg,jpeg,bmp,png,gif',upFlashUrl:'upload.php',upFlashExt:'swf',upMediaUrl:'upload.php',upMediaExt:'wmv,avi,wma,mp3,mid'});

});

</script>


...




<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'news-form',

	'enableAjaxValidation'=>false,

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'content'); ?>

		<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>

		<?php echo $form->error($model,'content'); ?>

	</div>



open your browser and a editor is displayed.

view:

NOTE: moved to proper section