Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only variables should be passed by reference -ckeditor -codeigniter

I try to make text editor using ckeditor in my codeigniter project. But I always get Only variables should be passed by reference error whenever I call method display_ckeditor from my view.

This is my error log:

A PHP Error was encountered

Severity: Runtime Notice

Message: Only variables should be passed by reference

Filename: helpers/ckeditor_helper.php

Line Number: 65

Backtrace:

File: /var/www/html/webapp/webappadmin/application/helpers/ckeditor_helper.php
Line: 65
Function: _error_handler

File: /var/www/html/webapp/webappadmin/application/helpers/ckeditor_helper.php
Line: 90
Function: cke_create_instance

File: /var/www/html/webapp/webappadmin/application/views/ubahabout.php
Line: 7
Function: display_ckeditor

File: /var/www/html/webapp/webappadmin/application/controllers/Controll.php
Line: 187
Function: view

File: /var/www/html/webapp/webappadmin/index.php
Line: 292
Function: require_once

Here's my controller that load view:

public function ubahabout($id,$tab,$lang){
    //Ckeditor's configuration
    $data['ckeditor'] = array(

        //ID of the textarea that will be replaced
        'id'    =>  'content',
        'path'  =>  'js/ckeditor',

        //Optionnal values
        'config' => array(
            'toolbar'   =>  "Full",     //Using the Full toolbar
            'width'     =>  "550px",    //Setting a custom width
            'height'    =>  '100px',    //Setting a custom height

        ),

        //Replacing styles from the "Styles tool"
        'styles' => array(

            //Creating a new style named "style 1"
            'style 1' => array (
                'name'      =>  'Blue Title',
                'element'   =>  'h2',
                'styles' => array(
                    'color'     =>  'Blue',
                    'font-weight'   =>  'bold'
                )
            ),

            //Creating a new style named "style 2"
            'style 2' => array (
                'name'  =>  'Red Title',
                'element'   =>  'h2',
                'styles' => array(
                    'color'         =>  'Red',
                    'font-weight'       =>  'bold',
                    'text-decoration'   =>  'underline'
                )
            )               
        )
    );
    $data['myid']=$id;
    $data['mylang']=$lang;
    $data['mytab']=$tab;
    $this->load->view('ubahabout',$data);    // <---- ERROR GOES HERE
}

and this is my view (ubahabout.php):

<div class="main-container">
<?php
$content = $this->contentmodel->load_main_content_by_id($myid);
?>
<textarea name="content" id="content" ><p>Example data</p></textarea>
<?php 
echo display_ckeditor($ckeditor);     // <---- ERROR GOES HERE ?>

</div>

The error points out to the line 90 and 65 inside ckeditor_helper.php, and I still couldn't figure out what's the problem. Here's those line in ckeditor_helper.php:

line 90: $return .= cke_create_instance($data);,

line 65: if($k !== end(array_keys($data['config']))) {

Please help me. Thanks in advance.

like image 412
Subkhan Sarif Avatar asked Jul 04 '26 08:07

Subkhan Sarif


1 Answers

i also had this problem, The problem is not your script but the file 'helpers/ckeditor_helper.php' as shown from the error message.

The lines 65, 108, 116 each have the same issue. Instead of running the array_keys function inside the 'end()', assign to a variable first, then use the variable in the function.

helpers/ckeditor_helper.php

64.         $endkeys = (array_keys($data['config']));
65.         if($k !== end($endkeys)) {
107.        $endkeys2 = array_keys($v['styles']);
108.        if($k2 !== end($endkeys2)) {
115.        $endkeys3 = array_keys($data['styles']);
116.        if($k !== end($endkeys3)) {

That should take care of the issue.

like image 50
Adibas03 Avatar answered Jul 05 '26 21:07

Adibas03