简体   繁体   中英

How use Jquery image cropping plugin in codeigniter?

Jquery image cropping

I used Jquery image cropping plugins in my ci project, but here I facing problem in php file. while I load model in constructure its showing undefined error .

<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Cropavatar extends CI_Controller {
    private $src;
    private $data;
    private $dst;
    private $type;
    private $extension;
    private $msg;



  function __construct($src, $data, $file) {
    $this -> setSrc($src);
    $this -> setData($data);
    $this -> setFile($file);
    $this -> crop($this -> src, $this -> dst, $this -> data);
    $this->load->model('file_manager_model', 'file_manager');
  }

above is my code and here showing below error

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Cropavatar::$load

Filename: controllers/cropavatar.php

Line Number: 20

Note: I refer from this https://github.com/fengyuanchen/cropper/tree/master/examples/crop-avatar

Put crop.php in libraries folder,

and in your controller load library,

$this->load->library('crop');

Ref : https://codeigniter.com/user_guide/general/creating_libraries.html

and in class ( crop.php )

Modify From :

function __construct($src, $data, $file) {
    $this -> setSrc($src);
    $this -> setData($data);
    $this -> setFile($file);
    $this -> crop($this -> src, $this -> dst, $this -> data);
}

To:

function __construct($args=array())
{
   if(!empty($args)){

    $params = args[0];

    $this->setSrc($params[0]);
    $this->setData($params[1]);
    $this->setFile($params[2]);

    $this->crop($this->src, $this->dst, $this->data);
   }
}

Looks like below :

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Cropavatar extends CI_Controller {


  function __construct() {

    // load library 
    // In the library loading function you can dynamically pass data as an array 
    // via the second parameter and it will be passed to your class constructor:

    $params = array('source', 'data', 'file');

    $this->load->library('crop', $params);



    $this->load->model('file_manager_model', 'file_manager');


   }
}   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM