Custom Plugin

More
11 years 7 months ago #47841 by MikeSantana
Custom Plugin was created by MikeSantana
We had created a custom Flexicontent Plugin.

The plugin is working but I want to be able to call my methods from trunk/public_html/components/com_flecicontent/templates/category.php

I would like to call it as $this->mymethodname_here

where my "mymethodname_here" would depend from a variable.

Sample of my plugin Class code:
Plugin file name: Mykecode.php:
<?php defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.event.plugin');
class plgFlexicontentMikecode extends JPlugin {
function plgFlexicontentMikecode(&$subject, $params) {
parent::__construct($subject, $params);
}
function renderCatItems()
{...}
}
?>
Flexicontent/template file name: category.php:
$cat_sections = $this->params->get(...);
foreach ($cat_sections as $cat_section){
$section= 'renderCat'.ucfirst($cat_section);
##### AT THIS MOMENT IT IS WORKING LIKE THIS ####
plgFlexicontentMikecode::$section();
###### HERE IS WHAT I WOULD LIKE ####
$this->$section; OR
$this->'renderCat'.ucfirst($cat_section);
}

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

More
11 years 7 months ago #47855 by micker
Replied by micker on topic Custom Plugin
i think you are in wrong category not ? (flexicaccess and not ion develloper ?)

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

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

More
11 years 7 months ago #47943 by MikeSantana
Replied by MikeSantana on topic Custom Plugin
Where should I post the message if custom plugin is not the place?

Mike

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

More
11 years 7 months ago #47947 by micker
Replied by micker on topic Custom Plugin
moved

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

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

More
11 years 7 months ago #47951 by ggppdk
Replied by ggppdk on topic Custom Plugin
Hello

if you want to call functions from inside any file via URL then you can do it as any PHP script,
... ...

but
-- you can call (via AJAX call or HTTP url) functions inside a flexicontent plugin file, our frontend controller supports this !!

Calling FLEXIcontent field functions as controller TASKs


-- 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 review. Thanks!

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

More
11 years 7 months ago #47989 by MikeSantana
Replied by MikeSantana on topic Custom Plugin
Hi Emmanuel;

I do not want to call the function via URL.

I am executing /components/com_flexicontent/templates/category.php
I have a plugin installed in /plugins/flexicontent/myplugin.php

Within category.php:
##### AT THIS MOMENT IT IS WORKING LIKE THIS ####
$section = 'renderCat'.ucfirst($cat_section); NOTE:$cat_section is received with a string value like 'items', or 'subcats'

plgFlexicontentMyplugin::$section();


I want to avoid the need of calling my methods separated from the method available to my $this at the moment of components/com_flexicontent/templates/category.php instance.

###### HERE IS WHAT I WOULD LIKE ####
$this->$section; which it is the equivalent of $this->'renderCat'.ucfirst($cat_section);
}

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

More
11 years 7 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 review. Thanks!

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

More
11 years 7 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.

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

More
11 years 7 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 review. Thanks!

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

More
11 years 7 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.

Moderators: vistamediajoomlacornerggppdk
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
Save