Advertisement
enkuso

симфонид ckeditor ашиглах.

Jun 25th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. /**
  2.  * qzWidgetFormCKEditor.class.php файл үүсгэж lib хавтсанд хуул.
  3.  */
  4.  
  5. <?php
  6.  
  7. class qzWidgetFormCKEditor extends sfWidgetFormTextarea {
  8.  
  9.   protected $_editor;
  10.   protected $_finder;
  11.  
  12.   protected function configure($options = array(), $attributes = array())
  13.   {
  14.     $editorClass = 'CKEditor';
  15.       if (!class_exists($editorClass))
  16.       {
  17.       throw new sfConfigurationException(sprintf('CKEditor class not found'));    
  18.       }
  19.     $this->_editor = new $editorClass();
  20.     $this->_editor->basePath = sfConfig::get('app_ckeditor_basePath');
  21.     $this->_editor->returnOutput = true;
  22.     if(sfConfig::get('app_ckfinder_active', false) == 'true')
  23.     {
  24.       $finderClass = 'CKFinder';
  25.       if (!class_exists($finderClass))
  26.       {
  27.           throw new sfConfigurationException(sprintf('CKFinder class not found'));    
  28.       }      
  29.       $this->_finder = new $finderClass();
  30.       $this->_finder->BasePath = sfConfig::get('app_ckfinder_basePath');
  31.       $this->_finder->SetupCKEditorObject($this->_editor);
  32.     }
  33.     if(isset($options['jsoptions']))
  34.     {
  35.       $this->addOption('jsoptions', $options['jsoptions']);    
  36.     }
  37.     parent::configure($options, $attributes);
  38.   }
  39.  
  40.   public function render($name, $value = null, $attributes = array(), $errors = array())
  41.   {
  42.     $jsoptions = $this->getOption('jsoptions');
  43.     if($jsoptions)
  44.     {  
  45.       $this->setJSOptions($name, $value, $attributes, $errors);
  46.     }
  47.     return parent::render($name, $value, $attributes, $errors).$this->_editor->replace($name);
  48.  
  49.   }
  50.   protected function setJSOptions($name, $value = null, $attributes = array(), $errors = array())
  51.   {
  52.     $jsoptions = $this->getOption('jsoptions');
  53.     foreach($jsoptions as $k => $v)
  54.     {
  55.       $this->_editor->config[$k] = $v;
  56.     }
  57.   }
  58.   public function getEditor()
  59.   {
  60.     return $this->_editor;
  61.   }  
  62.   public function getFinder()
  63.   {
  64.     return $this->_finder;
  65.   }  
  66. }
  67.  
  68. /**
  69.  * form-ийн configure method-д нэмэх.
  70.  */
  71.       $this->widgetSchema['body'] = new qzWidgetFormCKEditor(array(
  72.                 'label' => 'Агуулга',
  73.                 'jsoptions'=>array(
  74.                     'language' => 'mn',
  75.                     'toolbar'  => 'Basic'
  76.                 ),
  77.             ));
  78.  
  79. /**
  80.  * app.yml файлд нэм
  81.  */
  82. all:
  83.   ckeditor:
  84.     basePath:         '/ckeditor/'
  85.  
  86. /**
  87.  * ckeditor татаж аваад задал
  88.  */
  89.  
  90. татаж авах: http://ckeditor.com/download
  91. задлах зам: yourProject/web/ckeditor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement