if ($this->taste_array) {
foreach ($this->taste_array as $one) {
if (!in_array($one, $arr)) {
$model = ($model = HasProductTaste::find()
->where(['product_id' => $this->id])
->andWhere(['taste_id' => $one])
->one()) ? $model : new HasProductTaste();
$model->product_id = $this->id;
$model->taste_id = $one;
$model->save();
}
if (isset($arr[$one])) {
unset($arr[$one]);
}
}
}
sudo apt-get install php5-xdebug -y
sudo nano /etc/php5/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.default_enable=1
xdebug.var_display_max_depth=6
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1
xdebug.remote_log=/tmp/xdebug.log
xdebug.idekey="PHPSTORM"
xdebug.profiler_enable_trigger=1
xdebug.profiler_enable=0
xdebug.profiler_output_dir=/tmp/profiler
xdebug.show_local_vars=1
xdebug.overload_var_dump=1
/**
* Строим дерево категории
*
* @param $data
* @param int $rootID
* @return array
*/
protected function buildTree($data, $rootID = 0)
{
$tree = [];
foreach ($data as $id => $node) {
if ($node['parent_id'] == $rootID) {
unset($data[$id]);
$node['childs'] = $this->buildTree($data, $node['id']);
$tree[] = $node;
}
}
return $tree;
}
/**
* Получаю все категории
*
* @return array
*/
public function getAllCategories()
{
$data = Category::find()->asArray()->all();
return $this->buildTree($data);
}
$tree = $model->getAllCategories();
return $this->render('profile', ['tree' => $tree]);
foreach ($tree as $cat) {
// root 1-й уровень
echo $cat['title'];
if ($cat['childs'] > 0) {
foreach ($cat['childs'] as $childs) {
// category 2-й уровень
if (empty($childs['childs'])) {
echo $childs['title'];
} else {
echo '<b><br/>' . $childs['title'] . '</b><br/>';
}
foreach ($childs['childs'] as $child) {
// category 3-й уровень
echo $child['title'];
}
}
}
echo '</div>';
}