S
S
SlimSavernake2016-06-09 16:41:15
Yii
SlimSavernake, 2016-06-09 16:41:15

How to show phone from database in yii2 using pjax?

$model->phone - phone in the database
There is a link on the page

<a href="#" class="phone-number">Показать телефон</a>
.
Tell me, please, how when you click on a link, show the phone number instead.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Greg Popov, 2016-06-09
@Gregpopov

Here is an example for you, but you do not understand what you are saying.

D
Dmitry Kim, 2016-06-09
@kimono

It can be something like this:

// PhoneView
Pjax::begin(['enablePushState' => false, 'timeout' => 2000]);
if (isset($phone)){
  echo Html::tag('b', 'Вот ваш телефон: '.$phone);
}
else {
  echo Html::a('Показать телефон', ['/phone/show', 'id' => $model->id]);
}
Pjax::end();
// PhoneController
public function actionView($id){
  if (null !== $model = Phones::find(['id' => $id])){
    return $this->render('PhoneView', ['model' => $model]);
  }
  throw new NotFoundException();
}
public function actionShow($id){
  if (null !== $model = Phones::find(['id' => $id])){
    return $this->render('PhoneView', ['model' => $model, 'phone' => $model->phone]);
  }
  throw new InvalidParamException();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question