2017-10-06 42 views
-1

jQuery的图像裁剪如何在codeigniter中使用Jquery图像裁剪插件?

我用jQuery的剪切图像在我的CI项目的插件,但在这里,我在PHP文件面临的问题。而我在建筑中加载模型显示未定义的错误。

<?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 

甲PHP错误遇到

严重性:注意

消息:未定义的属性:Cropavatar :: $负载

文件名:控制器/ cropavatar.php

行号:20

注:我从这个 https://github.com/fengyuanchen/cropper/tree/master/examples/crop-avatar

+0

分享您的代码,请 – AZinkey

+0

@azinkey,你可以给任何解决方案。 –

+0

我想你应该添加crop.php作为库,而不是控制器 – AZinkey

回答

0

指把crop.phplibraries文件夹,

,并在控制器中加载库,

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

编号:https://codeigniter.com/user_guide/general/creating_libraries.html

和类(crop.php

修改来源:

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

要:

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); 
    } 
} 

看起来象下面这样:

<?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'); 


    } 
} 
+0

好的试试这个。 –

+0

$参数值没有在crop.php库文件中找到,我print_r($ params);死;但没有显示。 –

+0

如上所述 –