Welcome Guest, Not a member yet? Register   Sign In
Modular CI uploading problem
#1

[eluser]the_unforgiven[/eluser]
Hi All,

I have setup an application using modular CI from wiredesignz and set up a MY_Model.

Now in the model specific to this module i have a validation check:

Code:
public function validation_rules()
{

  return array(
   'title' => array(
    'field' => 'title',
    'label' => 'Page Title',
    'rules' => 'required'
   ),
   'image' => array(
    'field' => 'userfile',
    'label' => 'Image',
    'rules' => 'callback__do_upload_file|trim' // This doesn't seem to work for what ever reason, so this is what i am referring to that doesnt work!
   ),
   'status' => array(
    'field' => 'status',
    'label' => 'Please select',
    'rules' => 'required'
   )
  );
  
}

MY_Model - >http://pastebin.com/FpaF0mvk
Module Controller -> http://pastebin.com/kQvGypP9
Form itself ->http://pastebin.com/e57f2bn0

The do_upload function is located in wc_portlets.php inside modules>portlets>models>wc_portlets.php and has this on -> http://pastebin.com/KeEiev3G

among other stuff which isn't relevant.
So the do_upload should i move that to the MY_Model firstly and then how would i call it in the rules array shown above?

HELP, massively appreciated.

Cheers
Smile
#2

[eluser]the_unforgiven[/eluser]
Anyone want to help me on this please?
#3

[eluser]TheFuzzy0ne[/eluser]
I suspect it's because your callbacks need to be one of the following.

1) A method in your controller
2) A function
3) A method in the form validation library, either existing, or if you extend the validation library.
#4

[eluser]the_unforgiven[/eluser]
I have added this:

Code:
public function _do_upload_file()
{

     //upload config
  $config = array(
    'allowed_types' => '*', //jpg|jpeg|gif|png|pdf|JPEG|PNG|JPG|GIF|tiff|PDF
    'upload_path'   => $this->gallery_path,
    'max_size'      => 50000, //50MB limit
    'overwrite'     => false, //Doesnt overwrite exsisting
      'remove_spaces' => true, // Removes any white space
      'encrypt_name'  => true // Encrypt file name
  );
  
     $this->load->library('upload', $config);
   $this->upload->initialize($config);  
  
  
     if (!$this->upload->do_upload())
     {
         $this->form_validation->set_message('_do_upload_file', $this->upload->display_errors());
         return FALSE;
     }
     else
     {
  // Resize Config
   $config['image_library'] = 'gd2';
   $config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
   $config['new_image'] = $this->gallery_path . '/thumbs';
   $config['maintain_ratio'] = TRUE;
   $config['width'] = 150;
   $config['quality'] = '100%';
   $config['height'] = 150;
  
   /* echo $this->upload->upload_path.$this->upload->file_name . "<BR>";  */
  
   $this->load->library('image_lib', $config);
   $this->image_lib->initialize($config);
   $this->image_lib->resize();
    
   if (!$this->image_lib->resize()){
          $this->form_validation->set_message('_do_upload_file', $this->upload->display_errors());              
   }
  
  
  }

}

To the controller, but still no joy, any idea's
#5

[eluser]the_unforgiven[/eluser]
It's uploading to the folder but not saving to the database.

Here's the code all in one link > http://pastebin.com/e6yX7L7M



#6

[eluser]TheFuzzy0ne[/eluser]
Did you read the help file for MXHMVC?

It says:

When using form validation with MX you will need to extend the CI_Form_validation class as shown below,
Code:
&lt;?php
/** application/libraries/MY_Form_validation **/
class MY_Form_validation extends CI_Form_validation
{
    public $CI;
}

before assigning the current controller as the $CI variable to the form_validation library. This will allow your callback methods to function properly. (This has been discussed on the CI forums also).
Code:
&lt;?php
class Xyz extends MX_Controller
{
    function __construct()
    {
        parent::__construct();

        $this->load->library('form_validation');
        $this->form_validation->CI =& $this;
    }
}
#7

[eluser]TheFuzzy0ne[/eluser]
Also, if the image cannot be resized, you set the message using $this->upload->display_errors(). It would probably make more sense to show the error from the image_lib object, since there won't be an error from the uploads library. Wink
#8

[eluser]the_unforgiven[/eluser]
looks like:

Code:
class Form_Validation_Model extends MY_Model {
    

    public function __construct()
    {
       parent::__construct();

        $this->load->library('form_validation');
        $this->form_validation->CI =& $this;
    }
    
}
#9

[eluser]TheFuzzy0ne[/eluser]
You are extending MY_Model, and you need to extend CI_Form_validation:

Code:
class MY_Form_validation extends CI_Form_validation {
    
    public function __construct()
    {
         parent::__construct();

          $this->load->library('form_validation');
          $this->form_validation->CI =& $this;
    }
    
}
#10

[eluser]the_unforgiven[/eluser]
No I get :


A PHP Error was encountered

Severity: Notice

Message: Undefined property: Wc_pages::$load

Filename: core/Form_Validation_Model.php

Line Number: 14

Fatal error: Call to a member function library() on a non-object in /Applications/MAMP/htdocs/site/application/core/Form_Validation_Model.php on line 14




Theme © iAndrew 2016 - Forum software by © MyBB