Override data_sources/com_content/model.php

News Show Pro GK5 - flexible, responsive and easily extendable free Joomla module support forum.
Rate this topic: Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.
GK User
Wed Mar 09, 2016 7:45 pm
Is it possible to override the file data_sources/com_content/model.php inside the template?
I have tried these without success:
- joomla/templates/mytemplate/html/mod_news_pro_gk5/model.php
- joomla/templates/mytemplate/html/mod_news_pro_gk5/data_sources/com_content/model.php

I have extra columns in my content table and I want to select a different column instead of 'introtext'. I was able to do it changing the main module files but this way I cannot update the module anymore.
User avatar
Fresh Boarder

teitbite
Sun Mar 13, 2016 12:20 pm
Hi

I'm afraid this is not possible. Those are too important files in components to be allowed to be changed. Overrides in template can be done to layouts only. So basically You can change the look, but not the functionality.

Anyway You can use layout files in override and add the extra code to pick up additional elements from database.
User avatar
Moderator

GK User
Sun Mar 13, 2016 4:23 pm
Thank you very much for your reply and for taking the time!

Could you tell me how would i change default.php or view.php to add this:
'content.intro_text AS eye'

If that's not too much trouble.

Luciana
User avatar
Fresh Boarder

teitbite
Thu Mar 17, 2016 12:09 pm
Hi

It's not a trouble, but I simply do not know what You need that for? Here how the PHP code should looks like for article view.

Code: Select all
<?php
$db = JFactory::getDbo();

// Query
$query = "SELECT content.intro_text AS eye FROM #__content AS content WHERE content.id = " . $this->item->id . ";";
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
$results = $db->loadObjectList();
?>
User avatar
Moderator

GK User
Thu Mar 17, 2016 2:46 pm
I tryed that on default.php for mod_news_show_pro_gk5 and it didnt worked.
I got: Error while rendering position

I want that because i created a new column for the table content that shows a introtext used in news websites, a lead. I already have a plugin to load that content in articles. Check it out:
Image

But I'd like to show that also in mod_news_show_pro_gk5. :D
User avatar
Fresh Boarder

teitbite
Tue Mar 22, 2016 10:43 am
Hi

For NSP it would be the same job and code, just in the style layout of Your choosing. I'm sorry I cannot help more, but it's beyond our support.

Error while rendering position


??????

There is nothing in this piece of code that is being rendered or creating a position. Must be an issue in a different place of the file.
User avatar
Moderator

GK User
Mon Mar 28, 2016 10:49 pm
Thank you for your help so far teitbite.
I will just keep updating the core model.php file with the code that I was able to work on. =)

For the record:
1) Created adittional table in xxx_content called intro_text
2) Edited data_sources/com_content/model.php line 287:
Code: Select all
                // second SQL query to get rest of the data and avoid the DISTINCT
                $second_query_news = '
                SELECT
                        content.id AS iid,
                        '.($config['use_title_alias'] ? 'content.alias' : 'content.title').' AS title,
                        content.'.$config['com_content_text_type'].' AS text,
                        content.'.($config['date_publish'] == 0 ? 'created' : ($config['date_publish'] == 1 ? 'publish_up' : 'publish_down')).' AS date, 
                        content.publish_up AS date_publish,
                        content.intro_text AS lead,
                        content.hits AS hits,
                        content.images AS images,
                        content.featured AS frontpage,
                        content.access AS access,
                        content.language AS lang,
                        categories.title AS catname,
                        users.email AS author_email,
                        content.created_by_alias AS author_alias,
                        '.$config['username'].' AS author_username,
                        content_rating.rating_sum AS rating_sum,
                        content_rating.rating_count AS rating_count,
                        CASE WHEN CHAR_LENGTH(content.alias)
                                THEN CONCAT_WS(":", content.id, content.alias)
                                        ELSE content.id END as id,
                        CASE WHEN CHAR_LENGTH(categories.alias)
                                THEN CONCAT_WS(":", categories.id, categories.alias)
                                        ELSE categories.id END as cid

3) Created overrride in template folder: templates/g5_hydrogen/html/mod_news_pro_gk5/view.php line 78, i can either replace $item['text'] or add $item['lead'].
Code: Select all
               $output_html = '<p class="nspText'.$class.'">';
                $output_html .= $item['lead'];
                $output_html .= $item['text'];
//$output_html .= print_r($item, true);
                if($config['news_content_readmore_pos'] == 'after') {
                        $output_html .= ' ' . $readmore;
                }
                $output_html .= '</p></div>';
User avatar
Fresh Boarder

teitbite
Sat Apr 02, 2016 9:53 am
Hi

This solution looks pretty good. Thank You for posting that. Hopefully some other users can benefit from that. Leaving thread open in case You will want to share more.
User avatar
Moderator


cron