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 7087199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:38:40+00:00 2026-05-28T07:38:40+00:00

Normally a widget is used by calling CController::widget() on an instance of CController ,

  • 0

Normally a widget is used by calling CController::widget() on an instance of CController, typically $this in a view.

But if I’m writing a static method, a helper, say, then I don’t have access to an instance of CController. So how do I use a widget?

Let’s say further that this helper method is invoked in the eval()’ed expression in a CDataColumn‘s value property. That poor expression has almost no context at all. How should the helper use a widget?


EDIT: Code example

As requested, a view example:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $model->search(),
    'columns' => array(
        array(
            'name' => 'attrName',
            'value' => '--USE WIDGET HERE--',
        ),
    )
));
  • 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-05-28T07:38:41+00:00Added an answer on May 28, 2026 at 7:38 am

    This answer doesn’t answer the question in general but in the specific case—how to access the controller and use a widget in the context of the evaluated expression of CDataColumn::$value—you can use this:

    $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $model->search(),
        'columns' => array(
            array(
                'name' => 'attrName',
                'value' => function ($data, $row, $column) {
                    $controller = $column->grid->owner;
                    $controller->widget(/* ... etc ... */);
                }, 
            ),
       )
    ));
    

    The trick was discovering that CDataColumn::renderDataCellContent() uses CComponent::evaluateExpression(), which injects the component instance into the callback as the last parameter. In this case that omponent is the CDataColumn, which references the controller as shown.

    I don’t like writing PHP expressions as string literals so I’m pleased to find this option.

    A comment on http://www.yiiframework.com/doc/api/1.1/CDataColumn#value-detail shows another way to us a widget in a column value that I haven’t tried.

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

Sidebar

Related Questions

NEW INFO: Something I just noticed (because this isn't something I'd normally do), but
Something like this, would make the widget appear normally: Label(self, text = 'hello', visible
Normally I use imagecreatefromjpeg() and then getimagesize() , but with Firefox 3 I need
Normally you can do this: <select size=3> <option>blah</option> <option>blah</option> <option>blah</option> </select> And it would
Normally, the method of passing workflow parameters to the workflow happens in the call
Normally I create web application projects and use code-behind, but I have a requirement
Can the dojo.query function be used to lookup widgets with certain attributes? for instance,
I used jQuery tabs widget in my page with ajax mode, something like <li><a
Normally, I'd do getString(R.string.myString), however it doesn't seem to work in a widget.
This should be the easiest thing in the world, but a POST redirect is

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.