T
T
Test Test2015-11-05 12:13:23
Yii
Test Test, 2015-11-05 12:13:23

How to correctly assign a value to a variable in a Yii controller?

Hey!
For example, we have this view.php:

<?php if ($this->beginCache('item', array(
    'duration' => Yii::app()->params['cacheDuration'],
    'dependency' => array(
      'class' => 'system.caching.dependencies.CDbCacheDependency',
      'sql' => 'SELECT MAX(update_time) FROM {{items}}'
    ),
  ))) { ?>
  <?php $this->widget('AMListView', array(
    'id' => 'items',
    'dataProvider' => $dataProvider,
    
    'pager' => array(
      'class' => 'AMLinkPager',
    ),
  )); ?>
  <?php $this->endCache(); } ?>

AMLinkPager.php is an overridden class of CLinkPager.php. It has the following structure:
public function run() {
    $this->owner->owner->renderDynamic(array($this, "dynamic")); // Динамический рендер
  }

  public function dynamic() {
    if ($this->owner && $this->owner->owner) {
      $this->owner->owner->param =  'какое-то значение'; // !!!! вот этот параметр не ссетится в базовый контроллер (поведение) $this->owner->owner
 
                         print_r($this->owner->owner); // Но в дампе есть значение param!
    }

    // Какой-то код
    return $str;
  }

How to correctly assign a parameter to the base controller (behavior) if we have a cacheable block. If you clear the cache, then, logically, everything works only once. Thank you!
Or can you go some other way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Test Test, 2015-11-05
@cubooks

It turned out that everything is very simple:

$behavior = $this->controller->asa('yourController'); // или $this->getController();
$behavior->param = 'test';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question