View Snippet #220

      
  namespace frontend\components;
   
  use Yii;
  use yii\web\Controller;
  use common\models\Organization;
   
  /**
   * ActivityController implements the CRUD actions for Activity model.
   */
  class ZController extends Controller
  {
      
      public function init() {
          
          parent::init();
   
          if (Yii::$app->requestedRoute=='organization/view' || Yii::$app->getRequest()->getQueryParam('orgid')) {
              $id = (Yii::$app->requestedRoute=='organization/view') ? Yii::$app->getRequest()->getQueryParam('id') : Yii::$app->getRequest()->getQueryParam('orgid');
              $org = Organization::find($id)->asArray()->one();
              // make the name URL friendly
              $org = str_replace([' ','\'','"','-'],"_",$org);
              // store the data in params
              Yii::$app->params['organization_id'] = $id;
              Yii::$app->params['organization_name'] = $org['name'];
          }
          else
              Yii::$app->params['organization_id']=0;
          
      }
  }