Welcome Guest, Not a member yet? Register   Sign In
How to load images to Redactor editor using codeigniter?
#1

[eluser]mostafash[/eluser]
Hi,
I'm using Redactor editor on my project.
I want to load images from my folder to editor .This editor using json encode to call image thumb path and image path.
I use below code to show images in my editor but the editor didn't load any images:
in view page I use this code:
Code:
[removed]
$(document).ready(
function()
{
$('#description').redactor({  
  imageUpload: 'modul/editor_uploader.php',
  imageGetJson: '<?php echo $editor_images; ?>',
  lang : 'fa',
  direction: 'rtl',
});
}
);
[removed]

and I use this in my model:
Code:
var $gallery_path;
var $gallery_url;
var $images_path;
var $images_url;
public function __construct (){
  parent::__construct();
  $this->images_path=realpath(APPPATH.'../uploads/images');
  $this->images_url=base_url().'uploads/images/';
  $this->gallery_path=realpath(APPPATH.'../uploads/gallery');
  $this->gallery_url=base_url().'uploads/gallery/';
}
public function get_editor_images(){
   $files=scandir($this->images_path);
   $files=array_diff($files,array('.','..','thumbs','index.html'));
   $images=array();
   foreach($files as $file){
    $images[]=array(
     'thumb' => $this->images_url.'thumbs/'.$file,
     'image' => $this->images_url.$file
    );
   }
   return stripslashes(json_encode($images));
  }

and use this in controller:
Code:
$data['editor_images']=$this->File_model->get_editor_images();

But I can't see any images in my editor .
Can any one help me,plz Sad
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

Sorry, but I'm not familiar with the WYSIWYG editor you're using. Are you sure that your model is actually returning the data you expect? Why are you calling stripslashes() on the JSON, won't that mess up your paths?
#3

[eluser]mostafash[/eluser]
Hi,
Finally i find that ;-P
I Add a function to my view form called editor_images:
My code in the view :
Code:
[removed]
$(document).ready(
function()
{
$('#description').redactor({  
  imageUpload: 'modul/editor_uploader.php',
  imageGetJson: '<?php echo base_url() ?>admin/editor_images',
  lang : 'fa',
  direction: 'rtl',
});
}
);
[removed]

Call that editor_images using controller:
my controller :
Code:
public function editor_images(){
  echo $this->File_model->get_editor_images();
}


And my model :
Quote: var $images_path;
var $images_url;
public function __construct (){
parent::__construct();
$this->images_path=realpath(APPPATH.'../uploads/images/thumbs');
$this->images_url=base_url().'uploads/images/';
}
public function get_editor_images(){
$files=scandir($this->images_path);
$files=array_diff($files,array('.','..','thumbs','index.html'));
$images=array();
foreach($files as $file){
$images[]=array(
'thumb' => $this->images_url.'thumbs/'.$file,
'image' => $this->images_url.$file
);
}
return stripslashes(json_encode($images));
}

Just it :-)




Theme © iAndrew 2016 - Forum software by © MyBB