Answer the question
In order to leave comments, you need to log in
Why is the variable not getting into the yii2 session?
This is my Category.php model
public static function findOne($id)
{
$data = self::find()
->where(['id' => $id])
->one();
return $data;
}
public function actionAdd($id)
{
$item = Category::findOne($id);
$session = Yii::$app->session;
$session->set('item', $item);
return $this->render('list',['item' => Yii::$app->session->get("item")]);
}
use yii\helpers\Html;
use yii\helpers\Markdown;
<div class="btn-toolbar filters">
<input type="checkbox" value="Music" >
<?= Html::a('Add', ['site/add', 'id'=>$item->'1'], ['class' => 'btn btn-success'])?>
</label>
<label class="btn btn-default">
<input type="checkbox" value="Video" >
<?= Html::a('Add', ['site/add', 'id'=>$item->'2'], ['class' => 'btn btn-success'])?>
</label>
<label class="btn btn-default">
<input type="checkbox" value="Pictures" >
<?=$threecategory->title ?>
<?= Html::a('Add', ['site/add', 'id'=>$item->'3'], ['class' => 'btn btn-success'])?>
</label>
</div>
<?php
use \yii\helpers\Html;
use yii\widgets\LinkPager;
/* @var $this yii\web\View */
/* @var $products common\models\Product[] */
?
<p>Вы добавили категорию себе <a href="<?= Yii::$app->urlManager->createUrl(['site/add', 'item' => $item]) ?>"><?=$item ?>:</a></p>
Answer the question
In order to leave comments, you need to log in
I am glad for you that you have such listings, but here you have 2 options:
a) go to freelance and look for a person who will solve all your problems for money;
b) formulate your question normally and show that you tried to understand the problem, then perhaps they will help you.
I think people have begun to forget that Toaster is a site to help developers; a site in order to understand the problem and learn how to solve it, and not for smart uncles to solve someone's problems, giving ready-made solutions.
1. Yii has findOne($id) initially, why write a function in the model?
2. $session->set('item', $item); - sets, but does not add. You don't have an 'item' element in your session, so you should probably use $session->add('item', $item);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question