-2

I have written a plugin based on the content component. This works well as far as it goes but I would like to create a new field in the content table and use the field instead. I have got as far as adding the new field and I can see that when I access the onContentPrepare method the $data carries the variable and the value that I have manually entered into the database, but I don't seem to have anyway to a) display the value or b) save the value.

Could some kind soul point me in the right direction please.

2
  • 1
    Maybe you can share some snippets of your code? Jul 16, 2014 at 20:41
  • I haven't added any code because the code I have works fine but it only works on the field attribs. What I want to do is to use the value of another field which I can see is in the variable $data but I don't know how to display that data on a form on the administrator page. Jul 17, 2014 at 18:05

2 Answers 2

1

by editing the plugin live in your site and doing things like:

print_r($data)
exit;

You can see what the data is at any given point in the execution of the plugin. If it does nothing then you know an if statement is not returning true or the page you are on does not use the content plugin.

As for displaying the value in a page, you need something like loadposition, by refering to the file you can see how it pulls the article text and then replaces part of it with the code it needs.

$regex      = '/{loadposition\s(.*?)}/i';
preg_match_all($regex, $article->text, $matches, PREG_SET_ORDER);
if ($matches)
{
    foreach ($matches as $match)
    {
          $article->text = preg_replace("|$match[0]|", addcslashes($output, '\\$'), $article->text, 1);
    }
}

This just pulls part of that plugin out, but it shows the concept.

As for saving the value, if you just saved that value in the database, have you not just saved it? You say manually so I assume you mean in phpmyadmin or something. Refer to JDatabase in that case. http://docs.joomla.org/Accessing_the_database_using_JDatabase

1
  • If you are only going to use the fullstring matches then you don't need to write a capture group in your pattern and PREG_SET_ORDER can be omitted. I don't know for certain but if $match[0] may contain special characters that will confuse the regex engine, then preg_quote() should be called. Where does $output come from? Nov 30, 2018 at 12:34
0

Late answer, but we're doing just what you're asking with a slight difference. We store all the data in the article just like Joomla does as not to interfere with what Joomla and any other extensions might expect, but have an "extension" table for the article. That table has the same id as the article, but contains all the extra fields that we want to use with MySQL, etc.. It's fully described in my answer for How to Modify Article Structure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.