Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:07:53+00:00 2026-06-07T13:07:53+00:00

I’ve hit a small-ish problem while working with Yii framework. To explain the situation:

  • 0

I’ve hit a small-ish problem while working with Yii framework.
To explain the situation:
I have to create a sales-promotion slider of sorts. Each promotion consists of a url to more information about the promotion and an image url. Each promotion has several localized versions of it’s image. For this purpose I’ve created 2 database tables –
First is the promotions table:

CREATE TABLE IF NOT EXISTS `promotions` (  
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
  `title` varchar(100) NOT NULL,  
  `image` int(10) unsigned DEFAULT NULL,  
  `destination` varchar(200) NOT NULL,  
  `status` tinyint(3) unsigned NOT NULL DEFAULT '0',  
  PRIMARY KEY (`id`),  
  KEY `image` (`image`)  
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;  

and second is the promotion images table:

CREATE TABLE IF NOT EXISTS `promoImages` (  
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
  `pid` int(10) unsigned NOT NULL,  
  `language` varchar(2) NOT NULL,  
  `url` varchar(200) NOT NULL,  
  PRIMARY KEY (`id`),  
  KEY `language` (`language`),  
  KEY `mhm` (`pid`)  
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;  

The idea with such database structure is that in each promotions table row in the field image it contains an identifier for the appropriate image, then in table promoImages the related column pid contains the unique promotion identifier. Each promotion can be localized in several undefined languages, so for each image that is related to a single promotion there can be several rows in promoImages, an example of this:

INSERT INTO `promoImages` (`id`, `pid`, `language`, `url`) VALUES  
(1, 1, 'lv', '/path/to/image1_lv.png'),  
(2, 2, 'lv', '/path/to/image2_lv.png'),  
(3, 3, 'lv', '/path/to/image3_lv.png'),  
(4, 1, 'en', '/path/to/image1_en.png'),  
(5, 2, 'en', '/path/to/image2_en.png'),  
(6, 3, 'en', '/path/to/image3_en.png'),  
(7, 1, 'ru', '/path/to/image1_ru.png'),  
(8, 2, 'ru', '/path/to/image2_ru.png'),  
(9, 3, 'ru', '/path/to/image3_ru.png');  

Now with that structure in mind I also created a foreign key in table promotions which generated along with Yii frameworks “Gii” tool created models with such relations:
Table promotions model relation

'promoImages' => array(self::HAS_MANY, 'PromoImages', 'pid'),  

and table promoImages model relation

'p' => array(self::BELONGS_TO, 'Promotions', 'pid'),  

And as far as I know, the relation is correct, single promotion can have multiple promoImages table rows and any promoImages row can only belong to single promotion, as I correct to believe this is true?

I hope I’ve explained the situation as thoroughly as possible, now onto the issue itself.
As I mentioned at top, from all that I really only need to retrieve 2 values, 1 from each table: destination from promotions and url from promoImages but as I’m selecting these values I need to keep in mind only selecting those promotions whose status is “1” meaning that the promotion is active. Also when selecting the promotion image I need to select the row from table promoImages which corresponds to both the promotions image column aswell as current chosen application language(Yii::app()->language).

So far the code I have is as follows:
The promotion widget controller

public function run() {
    $l = Yii::app()->language;
    $promos = Promotions::model()->with('promoImages')->findAll('status=:status AND promoImages.language=:language', array(
        ':status' => 1,
        ':language' => $l
    ));

    $this->render('promo', array('promotions' => $promos));
}  

the promotion widget view

foreach ($promotions as $promotion) {
    // $image = $promotion->promoImages->url;
    $dest = $promotion->destination;
    echo "<div class='promo_hold'>";
        echo "<a href='$dest'><img src='$image'></a>";
    echo "</div>";
}  

This gives me the 3 div’s I need for the 3 active promotions but with empty images, if I uncomment the $image definition I get the Trying to get property of non-object error and this is basically where I’m stuck, I’ve looked at Yii’s class reference but so far it hasn’t gotten me any help.

If I’m missing any required information please don’t hesitate to ask.

Thanks beforehand!

P.S. I hope my wall of text doesn’t actually scare away people who might have an answer :O

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:07:54+00:00Added an answer on June 7, 2026 at 1:07 pm

    Okay so I found the answer to my question myself so I’ll add it as an answer here in-case someone else has a problem like this.
    While trying all kinds of variations to get the field I need I noticed that $promotion->promoImages is actually an array containing single element, the object that contains all the information relating to selected promotion and language.

    So I came to such a solution for this problem, in widgets foreach loop I simply set:

    $image = $promotion->promoImages[0]->url;
    

    And that is showing me the correct, language selected image address.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.