0

Our Yii Framework application has the following defined as part of the UserProfileImages model:

public function getProfileImages($param, $user_id) {
        if(isset($param['select']) && $param['select']=='all'){
            $profile_images = UserProfileImages::model()->findAllByAttributes( array( 'user_id'=>$user_id) );

        } else {
            $profile_images = UserProfileImages::model()->findByAttributes( array( 'user_id'=>$user_id) );
        }
        return $profile_images;
    }

How would I wire up the above snippet to a widget in my view to return all the images for a given user?
Bonus Question: Which image rotator do you suggest to render the above?

1 Answer 1

1

In your view file, add something like this, assuming that your controller specified $user_id:

$this->widget('UserProfileImagesWidget', array(
    "userProfileImages" => UserProfileImages::getProfileImages(
        array("select" => "all"), 
        $user_id
     ),
     "user_id" => $user_id
)); 

Depending on your MVC philosophy, you could also retrieve the userProfileImages data in the controller and pass that data to your view.

Define a widget like this:

class UserProfileImagesWidget extends CWidget {
    public $user_id;
    public $userProfileImages = array();

    public function run() {
        $this->render("userProfileImage");
    }
}

Finally, in the userProfileImages.php view file, you can do something like this:

if(!empty($this->userProfileImages)) {
    // Your display magic
    // You can access $this->user_id
}

As a side note: You might want to change the order of your parameters in getProfileImages. If $user_id is the first parameter, you can leave out $params completely in case you don't want to specify any.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.