Joomla - Where is the code in K2 which saves a new item's Title and alias

白昼怎懂夜的黑 提交于 2020-01-24 15:06:08

问题


I have looked every where in the administrator\components\com_k2 folder but am not able to find the code that saves a new item\article in K2. I checked the item.php file under models folder. No luck.

I need to override the K2 item save method.

I need a know the exact method that saves the Item's title and alias into the #__K2_content table.

I have to duplicate the K2 items in joomla articles on save and remove on trash/delete.

I have successfully been able to override the K2 core code. But am unable to find the right code to override. (override method is here)


回答1:


The table that stores the K2 items (at least in the latest K2 version - 2.6.5) is #__k2_items, not #__k2_content.

I went through the code, it looks like K2 uses Joomla's methods: see administrator/components/com_k2/controllers/item.php - line 24: function save(). Everything is extended from Joomla classes.

class K2ControllerItem extends K2Controller
{

    public function display($cachable = false, $urlparams = array())
    {
        JRequest::setVar('view', 'item');
        parent::display();
    }

    function save()
    {
        JRequest::checkToken() or jexit('Invalid Token');
        $model = $this->getModel('item');
        $model->save();
    }
    .....
}

The K2 controller: /administrator/components/com_k2/controllers/controller.php

...
else if (version_compare(JVERSION, '2.5', 'ge'))
{
    class K2Controller extends JController
    {
        public function display($cachable = false, $urlparams = false)
        {
            parent::display($cachable, $urlparams);
        }

    }

}
...



回答2:


@Shaz, you gave me the right direction to look into.

in com_k2\controllers\item.php this $model->save();saves the data.

The function save() is in the com_k2\models\item.php file, where there are two lines that capture the data.

$row = JTable::getInstance('K2Item', 'Table');

this initiates the $row, while

if (!$row->bind(JRequest::get('post')))

this populates $row.

So now $row contains all the variable values.

Now, this if (!$row->store()) saves the data.

I will use $row to save the same for the Joomla! articles in com_content.

Feels Good :)



来源:https://stackoverflow.com/questions/14990175/joomla-where-is-the-code-in-k2-which-saves-a-new-items-title-and-alias

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!