从zend表单更改ckeditor的高度 [英] Changing the height of ckeditor from a zend form

查看:196
本文介绍了从zend表单更改ckeditor的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试设置我使用的ckeditor的高度。这是我目前有的:

  $ this-> addElement('textarea','text_field',array $ b'filters'=> array('StringTrim'),
'validators'=> array(
array('StringLength',true,array(0,3000)),
),
'decorators'=> array('ViewHelper'),
'required'=> false,
'attribs'=& 'ckeditor'),
'label'=>'请在下面输入文字',
'value'=> isset($ this-> _text_data [0] ['text'])? $ this-> _text_data [0] ['text']:''
));

这来自我的表单,然后通过以下方式在我的.phtml文件中调用:

 <?= $ this-> element-> getElement('text_field')?> 

我看过无处不在,并尝试添加:

 'height'=> '100px',

和:

 'config'=> array(
'toolbar'=>'Full',
'width'=>'550px',
'height'=>'100px',

但这两个都没有工作。我需要这个的主要原因是我有一个文本区域(使用ckeditor为了允许输入信息以特定的方式格式化),这是相当长(我假设的默认高度),但它只有几个



提前感谢



Iain

我做了一个表单元素和帮助器使用 ZendX_JQuery_View_Helper_UiWidget 使用jQuery适配器创建CKEditor。这两个文件的代码:



ZendExt_Form_Element_CKEditor

  class ZendExt_Form_Element_CKEditor extends ZendX_JQuery_Form_Element_UiWidget 
{
/ **
*默认使用formCKeditor视图帮助
* @var string
* /
public $ helper ='formCKEditor';

/ **
*默认ckeditor选项
*
* @var数组
* /
public $ jQueryParams = array $ b'toolbar'=>'Basic'
);
}

ZendExt_View_Helper_FormCKEditor

  class ZendExt_View_Helper_FormCKEditor extends ZendX_JQuery_View_Helper_UiWidget 
{
static $ set = false;

public function formCKEditor($ name,$ value = null,$ params = null,$ attribs = null)
{
$ hTextA = new Zend_View_Helper_FormTextarea();
$ hTextA - > setView($ this - > view);
$ xhtml = $ hTextA - > formTextarea($ name,$ value,$ attribs);
$ xhtml。='< script type =text / javascript> $(document).ready(function(){$(#'。$ this-> _normalizeId($ name)。 ).ckeditor('。(!is_null($ params)?'function(){},'。Zend_Json_Encoder :: encode($ params):'')。')});< / script&
if(self :: $ set == false){
$ this - >视图 - > headScript() - > appendFile($ this - > view - > baseUrl()。'/js/ckeditor/ckeditor.js');
$ this - >视图 - > headScript() - > appendFile($ this - > view - > baseUrl()。'/js/ckeditor/adapters/jquery.js');
self :: $ set = true;
}
return $ xhtml;
}
}

您可以将其用作任何其他ZF表单元素您将这两个文件复制到:

* libraries / ZendExt / Form / Element / 用于 ZendExt_Form_Element_CKEditor

* libraries / ZendExt / View / Helper / for ZendExt_View_Helper_FormCKEditor
并在配置文件中添加了 ZendExt 命名空间(或者如果您已经有了一个库,并且希望使用它,只需将两个文件放入其中并更改反映你的类的名称)。然后,你将有tel ZF, ZendExt / View / Helper 是一个目录来查看视图助手(在.ini配置文件中它看起来像: resources.view.helperPath.ZendExt_View_Helper =ZendExt / View / Helper)。



$ ckEditor = new ZendExt_Form_Element_CKEditor(); 创建一个新的CKEditor。然后,您可以使用 $ ckEditor - >将所有需要的参数添加到元素。 setjQueryParam($ key,$ value); http://framework.zend.com/manual/fr/zendx.jquery.html 。例如: $ ckEditor - > setJQueryParam('height','100px'); 。我理解它不是一个jQuery组件,但它是最简单的方法,能够做到一切需要的地方。



要显示它,在你的视图do <?= $ this - >



请务必将 ckeditor.js 在/ js / ckeditor /下的公共目录中更改$ c>和 adapters / jquery.js ,或者在帮助程序中相应地更改路径。


I am trying to set the height of a ckeditor I am using. Here is what I currently have:

      $this->addElement('textarea', 'text_field', array(
        'filters'    => array('StringTrim'),
        'validators' => array(
            array('StringLength', true, array(0, 3000)),
        ),
        'decorators' => array('ViewHelper'),
        'required'   => false,
        'attribs'    => array('class' => 'ckeditor'),
        'label'      => 'Please enter text below',
        'value'      => isset($this->_text_data[0]['text']) ? $this->_text_data[0]['text'] : ''
    ));

This comes from my form, this is then called in my .phtml file by the following:

<?=$this->element->getElement('text_field')?>

I have looked everywhere and tried adding:

'height' => '100px',

and:

'config' => array(
          'toolbar' =>  'Full',     
          'width'   =>  '550px',    
          'height'  =>  '100px',
 ),

But neither of these have worked. The main reason I need this is I have a text area (using the ckeditor in order to allow the input information to be formatted in a particular way) which is quite long (the default height I am assuming) but it is only ever a few lines input into the box, hence the reason I want it smaller as it takes up too much space on the page.

Thanks in advance

Iain

解决方案

I made a form element and a helper using ZendX_JQuery_View_Helper_UiWidget to create a CKEditor with the jQuery adapter. Here's the code of both files :

ZendExt_Form_Element_CKEditor :

class ZendExt_Form_Element_CKEditor extends ZendX_JQuery_Form_Element_UiWidget
{
    /**
     * Use formCKeditor view helper by default
     * @var string
     */
    public $helper = 'formCKEditor';

    /**
     * Default ckeditor options
     *
     * @var array
     */
    public $jQueryParams = array(
        'toolbar' => 'Basic'
    );
}

And ZendExt_View_Helper_FormCKEditor :

class ZendExt_View_Helper_FormCKEditor extends ZendX_JQuery_View_Helper_UiWidget
{
    static $set = false;

    public function formCKEditor($name, $value = null, $params = null, $attribs = null)
    {
        $hTextA = new Zend_View_Helper_FormTextarea();
        $hTextA -> setView($this -> view);
        $xhtml = $hTextA -> formTextarea($name, $value, $attribs);
        $xhtml .= '<script type="text/javascript">$(document).ready(function(){$("#' . $this->_normalizeId($name) . '").ckeditor(' . (!is_null($params) ? 'function(){},' . Zend_Json_Encoder::encode($params) : '') . ')});</script>';
        if (self::$set == false) {
            $this -> view -> headScript() -> appendFile($this -> view -> baseUrl() . '/js/ckeditor/ckeditor.js');
            $this -> view -> headScript() -> appendFile($this -> view -> baseUrl() . '/js/ckeditor/adapters/jquery.js');
            self::$set = true;
        }
        return $xhtml;
    }
}

You can use it as any other ZF form element once you copied these 2 files into :
* libraries/ZendExt/Form/Element/ for ZendExt_Form_Element_CKEditor class
* libraries/ZendExt/View/Helper/ for ZendExt_View_Helper_FormCKEditor class
and added the ZendExt namespace in your configuration file (or if you already have a library of yours and want to use it, just put both files in it and change the name of the classes to reflect yours). Then, you'll have tel ZF that ZendExt/View/Helper is a directory to look in for view helpers (in a .ini config file it would look like : resources.view.helperPath.ZendExt_View_Helper = "ZendExt/View/Helper").

Then in your code, just call $ckEditor = new ZendExt_Form_Element_CKEditor(); to create a new CKEditor. You may then add all params you want to the element using $ckEditor -> setJQueryParam($key, $value); as specified in the documentation here : http://framework.zend.com/manual/fr/zendx.jquery.html . For example : $ckEditor -> setJQueryParam('height', '100px');. I understand it's not a jQuery component, but it was the easiest way to be able to make it as everything needed is available there.

To display it, in your view just do <?=$this -> ckEditor?> and you're good.

Make sure you put your ckeditor.js and adapters/jquery.js in your public directory under /js/ckeditor/ or change the path accordingly in the helper.

这篇关于从zend表单更改ckeditor的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆