vmichnowicz / vwm_secure_files

Lock down member and group-specific ExpressionEngine files
6 stars 0 forks source link

Matrix integration? #2

Open tyssen opened 13 years ago

tyssen commented 13 years ago

Another feature that would be cool is if the fieldtype could work with Matrix too.

vmichnowicz commented 13 years ago

All my EE projects so far have not required Matrix so I have yet to acquire a license. But if I ever get around to buying a copy I'll definitely take this into consideration.

tyssen commented 13 years ago

I've had a go at doing this myself but I've only got limited PHP skills and am running into an error: Unable to locate the model you have specified: vwm_secure_files_m. What's the best way to let you see the changes I've made?

vmichnowicz commented 13 years ago

The best way would be to fork the project and push your changes to your repository.

If you just have code from one or two files, you can create a gist

tyssen commented 13 years ago

I went for the second option as I only made a couple of minor mods to the fieldtype: https://gist.github.com/f6defbe5ee5a50b81805

vmichnowicz commented 13 years ago

Humm, I'm not really sure why it would be giving that error. You could try loading the model like so:

$this->EE->load->model('models/vwm_secure_files_m');

I kinda doubt that will do anything though. Also your _files_select method should be private. All the other methods should be public. And I don't believe there is any need to pass the field_name and field_id to your _files_select method.

The EE model loader is located in system/codeigniter/system/core/Loader.php. You code poke around in the model method to see what it is trying to load unsuccessfully.

Does the code work outside of Matrix?

tyssen commented 13 years ago

Yeah, changing $this->EE->load->model('vwm_secure_files_m'); to $this->EE->load->model('models/vwm_secure_files_m'); didn't do anything. So I tried hard-coding the path to the model into the file which let me save the field without producing the missing model error. But when going to the publish page, I now get this error:

Message: Undefined property: Content_publish::$vwm_secure_files_m Filename: vwm_secure_files/ft.vwm_secure_files.php Line Number: 73

Fatal error: Call to a member function all_files() on a non-object in ft.vwm_secure_files.php on line 73

I've updated the Gist with the latest code. And yes, what I had before was working OK for fields created outside Matrix.

vmichnowicz commented 13 years ago

There really should be a way to do this without require_once.

Maybe placing this in the constructor will work?

$this->EE =& get_instance();

If you have any EE addons that have fieldtype components that need to access a database table you could look at their code to see what they are doing. I have been looking around, but have yet to come across any that use models. Most just put the SQL right in the fieldtype...