Subkhan Sarif
Subkhan Sarif

Reputation: 469

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.

Upvotes: 3

Views: 2899

Answers (3)

Aswin TK
Aswin TK

Reputation: 118

Modify ckeditor_helper.php at system/helper

  1. $endkeys = (array_keys($data['config']));
  2. if($k !== end($endkeys)) {

  3. $endkeys2 = array_keys($v['styles']);

  4. if($k2 !== end($endkeys2)) {

  5. $endkeys3 = array_keys($data['styles']);

  6. if($k !== end($endkeys3)) {

151 $endkeys = array_values($key); 152 if($string !== end($endkeys)) $return .= ",";

160 $endkeys = array_values($data); 161 if ($key != end($endkeys)) $return .= ",";

Upvotes: 0

Adibas03
Adibas03

Reputation: 430

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.

Upvotes: 3

Panwen Wang
Panwen Wang

Reputation: 3825

I think the first argument of

$this->load->view('ubahabout',$data);

is a reference, just try:

$a = 'ubahabout';
$this->load->view($a, $data);

But not sure, you should also show the definition of $this->load->view

Upvotes: 0

Related Questions