2017-10-06 98 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

如上所述 –