billvv
Total posts: 55
15 Авг 2014 23:34

Sergey, Is it possible to access an SQL database from within my Plugin that uses 'onBeforeArticleSaved'?

This query code doesn't work (although it works in another program) but it's the general idea.

defined('_JEXEC') or die('Restricted access');


// Get VIN from hold_vin.

    $query = $db->getQuery(true);
        $holdid = 1;
        $query
           ->select('vin')
           ->from('hold_vin')
            ->where('id = ' . $db->quote($holdid));
    $db->setQuery($query);
    $vin = $db->loadResult();
//echo $vin;


require_once JPATH_ROOT . '/components/com_cobalt/api.php';
class plgMintVinpreload extends JPlugin
{
    public function onBeforeArticleSaved($isnew, $record, $section, $type)
    {
        if($isnew)
        {
            $app = JFactory::getApplication();
            if($app->isAdmin() || $app->input->getInt('section_id') != 6)
            {
                         return;
            }

etc.....


Последние изменения: 22 Авг 2014


Sergey
Total posts: 13,748
17 Авг 2014 09:01
  1. You have to put DB code inside the function.
  2. You forgot to define $db. Start with $db = JFactory::getDbo();.

billvv
Total posts: 55
18 Авг 2014 16:20

Got it, thanks. Works great!

One more question.... I want to hide the fields on the form, since I'm calculating their values. I created a blank 'Template on the Form' template (basically just 'defined('_JEXEC') or die();') and it seems to work. Will it break anything else if I do that?


Sergey
Total posts: 13,748
20 Авг 2014 10:18

I am not sure, you have to have some fields in the form, have you?


billvv
Total posts: 55
20 Авг 2014 20:02

Yes, there is another field in the test Section, and there will be quite a few other fields in the working Section.

This seems to work, just wondering if there's any side effects.

Also wonder if there is a way to hide the 'Post.....' portion of the menu, since I need to incorporate some error code into the VIN input - or, if there's somewhere I can insert the SQL error code in a Cobalt file. That would be ideal.

Presently, I run a 'POST' routine that does the error checking, stores the VIN and then offers a button that sends the user to the Cobalt form. The code in 'OnBeforeSave' grabs the VIN, stores it and the rest of the unique composite title fields, and the user is presented with the remaining fields to fill in. I don't want the user to select the 'Post' button in Cobalt and bypass the error checking; also, that will grab the last VIN stored, would probably be wrong.


Sergey
Total posts: 13,748
22 Авг 2014 11:22

billvv Also wonder if there is a way to hide the 'Post.....' portion of the menu,

In markup template parameters.

billvv just wondering if there's any side effects.

If it works I think it is ok.


billvv
Total posts: 55
22 Авг 2014 17:09

Thank you, works great!

Работает на Cobalt