Use Kohana MY_ in modules

mr.xy

Joined: 2011-09-20
Posts: 66
Posted: Fri, 2012-03-02 22:14

How can I use the MY_ prefix in modules (like the /locale folder in G2). I would like to keep the possibility to update modules without loosing certain customization.

Tried to modify the organize_event.php in a MY_organize_event.php and only got a blank page :-(
while the same modification in the original file does the wanted job.

It is about making the organize-module accessible only for admins.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25957
Posted: Sun, 2012-03-04 03:24

Does your new file extend the class organize_event_Core?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25957
Posted: Sun, 2012-03-04 08:04

What options do you want the module to have?
I have created a test module and I guess you only want the admin to be able to 'organize'?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25957
Posted: Sun, 2012-03-04 19:19

All I know is to build a module with MY_ to override other modules/core. That is why I asked what behavior you want for the organize.
perhaps another community member knows.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
mr.xy

Joined: 2011-09-20
Posts: 66
Posted: Mon, 2012-03-05 12:23

I thought the same way like in G2. I take the original file, modify it an name it MY_ (G2 -> put in subfolder /locale) and the system will now take the MY_ file instead of the original.

What I did: I took the organize_event.php and added in line 24 this:
&& identity::active_user()->admin

to make the organize-menu-entry only visible for admin-users.

The result was a blank page.

Do I replace the original file with a MY_ file? Wills the original file be ignored if there is a MY_ file?
Or do I place additional functions and overrides in an additionally used (MY_) file?

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25957
Posted: Mon, 2012-03-05 14:54

All I know is to build a module with MY_ to override other modules/core. I could be wrong.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25957
Posted: Tue, 2012-03-06 05:34

Well I can override helpers with MY_
what I did to test was: copied
gallery3/modules/helpers/organize_event.php
to
gallery3/modules/helpers/MY_organize_event.php
edited
class organize_event_Core {
to
class organize_event extends organize_event_Core {
Hope that helps.

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25957
Posted: Tue, 2012-03-06 05:40

Looking at the core gallery and gallery-contrib repository, I don't see one MY_ in a controller. I only see MY_ in helpers and library directories.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
mr.xy

Joined: 2011-09-20
Posts: 66
Posted: Tue, 2012-03-06 13:28

Thanks a lot floridave. Thats it:

Quote:
copied
gallery3/modules/helpers/organize_event.php
to
gallery3/modules/helpers/MY_organize_event.php
edited
class organize_event_Core {
to
class organize_event extends organize_event_Core {

It works.

Now updates may come :-)

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25957
Posted: Tue, 2012-03-06 14:27
floridave wrote:
Does your new file extend the class organize_event_Core?

That was not a big enough clue? I could have explained it better I guess.
Glad it is working for you as well.

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
fredhowe

Joined: 2012-05-28
Posts: 12
Posted: Mon, 2012-07-09 12:16

why do some files like "MY_album.php" are working well under my Path \themes\wind\helpers\MY_album.php,
and others like "MY_gallery_event.php" not.
This works only in the \modules\gallery\helpers\MY_gallery_event.php Path.

I would like to put all my custom made extended Classes in my Themes Path
and leave the core directory untouched.

And "MY_" Files under "/controllers/" doesen't work at all.

thanks in advance
Fred

 
mr.xy

Joined: 2011-09-20
Posts: 66
Posted: Wed, 2012-07-11 09:18

Maybe this can help you:
http://stackoverflow.com/questions/1309383/extending-the-template-controller-in-kohana

Especially the third answer:

Quote:
I know this is an old question, but I thought I'd put in a word. You just need to remove the MY_ prefix from the file name as you only really need it when extending a class suffixed with _Core in the system folder. For example, the file for

class Controller extends Controller_Core

would be named MY_Controller.php.

In this case, just naming the file baseController.php and putting it in the libraries folder would work.