Custom Plugin

More
9 years 9 months ago #47996 by ggppdk
Replied by ggppdk on topic Custom Plugin
Hello

now you call a method of PHP class statically

and you want to call the same method but on an instantiated object which of type:
class plgFlexicontentMyplugin


what you ask is a general PHP programming question,

to call function on an object do:
Code:
$a = new plgFlexicontentMyplugin(); $a->functionname();

but you already know this so i am not sure why you are asking this


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48016 by MikeSantana
Replied by MikeSantana on topic Custom Plugin
Hi Emmanuel;

I understand what you are saying but it is not what I want. I knew that I can create a new object by calling my new method. However this won't solve the issue that I have. I also tried your solution but it breaks the site.
Myplugin.php code is the following.
Code:
<?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport('joomla.event.plugin'); class plgFlexicontentMyplugin extends JPlugin { function plgFlexicontentMyplugin(&$subject, $params) { parent::__construct($subject, $params); // parent::__construct(); } function renderCatItems(){....} //THIS IS MY METHOD NEEDED TO BE CALL }

My category.php looks like
Code:
<?php defined( '_JEXEC' ) or die( 'Restricted access' ); // Category sections ordering $cat_sections = $this->params->get('layout_ordering',array("subcats","items")); if (is_array($cat_sections)){ echo '<div class="tmpl-'.str_replace('.category.','',$this->tmpl).' cat-'.$this->category->alias.'">'; foreach ($cat_sections as $cat_section){ if ($cat_section == 'items') { // Temporary to force testing my new method echo '<div class="myfunction">'; //$a = new plgFlexicontentMyplugin(); ### NOT WORKING it breaks the site. //$a = new plgFlexicontentMyplugin($this,); dump($this,'check for plgFlexicontentMyplugin'); // To dump $this and look for my methods available. The dump image is attached. $section= 'renderCat'.ucfirst($cat_section); plgFlexicontentMyplugin::$section(); //The way it currently works // $this->$section // The way I WOULD LIKE IT TO WORK echo '</div>'; } } echo '</div>'; } ?>
I would like that my classes from my method be accessible from $this in my ../component/com_flexicontent/templates/category.php

The option that you are suggesting basicaly would make me have my object $this and $a.
Again I would like to extend available method of my object $this in ../../../category.php

For example: I use joomla com_dump to dump my $this when it get to ../../category.php. I am able to see that $this has the method display available. (NOTE: check the image attached)

Imagine that I am creating my on ->display method.
So I would like to call it $this->display. but instead it would be $this->$section; which it is the equivalent of $this->'renderCat'.ucfirst($cat_section); => equivalent to $this->

Please let me know if you want to do a skype or join.me

Mike Santana.

PS: I sent you an email but it bounced.
Attachments:

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48018 by ggppdk
Replied by ggppdk on topic Custom Plugin
Hello

i am not Emmanuel :D

about using $this, you are in a different context,

$this is propably current VIEW object (anyway some other object), so you should not try to do it,

maybe you want to do this due to 3rd party code, anyway your question is a general PHP programming question

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48025 by MikeSantana
Replied by MikeSantana on topic Custom Plugin
Hello George. Sorry for the confusion.

Yes, $this should be VIEW object since i am calling it at ../components/com_flexicontent/templates/mytemplate/category.php

I am trying to do this not to a 3rd party code but my code. Like I said, we had created a plugin for flexicontent since we only work with flexicontnet. The plugin is installed in ../plugins/flexicontent/myplugin

If you think it is a simple PHP programming issue, could you be so kind and help me or point me how to solve the issue? I have not found how to extend the method available to my current object ($this in category VIEW). I even try to do what you said of creating my new object but it need 2 arguments for the construct ($subject, $params) that I don't know what to pass after trying couple things.

Please let me know;

Mike

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48026 by ggppdk
Replied by ggppdk on topic Custom Plugin
Hello

i did not say "simple"

out of
"simple PHP programming issue"

i said "general PHP programming question" ;)

if PHP does not allow this you should do it in a different way :)


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48027 by MikeSantana
Replied by MikeSantana on topic Custom Plugin
Hi George;

I got it ;)
I knew it was not a simple PHP thing. I was getting worried that I was missing something.

One last question:
In my plugin since it is the flexicontent plugin folder
should I have:
1-jimport('joomla.event.plugin'); // I have this
OR
2-jimport('joomla.plugin.plugin'); //flexinotify have this

I was checking the way you guys did the flexinotify plugin and it is different than what I have.

Anyways thank you for you fast respond

Mike

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.630 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline