FAQ по сетевой безопасности
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]);
}
}
}
Typeahead::widget([
'name' => 'city',
'options' => ['placeholder' => 'Все города'],
'pluginOptions' => ['highlight' => true],
'dataset' => [
[
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
'display' => 'value',
//'prefetch' => $baseUrl . '/samples/countries.json',
'remote' => [
'url' => Url::to(['/search/city']) . '?q=%QUERY',
'wildcard' => '%QUERY'
],
'templates' => [
'notFound' => '<div class="text-danger" style="padding:0 8px">Ничего не найдено.</div>',
]
]
],
]);
public function actionCity($q = null)
{
$cities = Profile::find()
->select(['concat(city_name, ", ",region_name) as value'])
->filterWhere(['like', 'city_name', $q])
->distinct()
->asArray()
->all();
$out = [];
foreach ($cities as $city) {
$c = explode(", ", $city['value']);
$outs[] = $c[0];
$outs[] = $c[1];
$city_name = implode(", ", $outs);
$out[] = ['value' => $city_name];
}
echo Json::encode($out);
}
для работы с PPA нужно установить необходимые инструменты:
apt-get install software-properties-common python-software-properties
После чего добавляем репозиторий, содержащий различные пакеты PHP:
add-apt-repository ppa:ondrej/php
В /etc/apt/sources.list.d/ появится файл со ссылкой на нужный нам репозиторий. После этого выполняем:
apt-get update
И уже можно устанавливать PHP 5.6:
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
foreach ($category as $k => $category_id) {
$profileHasCategory = ($profileHasCategory = ProfileHasCategory::find()->where(['user_id' => $user_id])->andWhere(['category_id' => $category_id])->one()) ? $profileHasCategory : new ProfileHasCategory();
$profileHasCategory->user_id = $user_id;
$profileHasCategory->category_id = $category_id;
$profileHasCategory->save(false);
}
/**
* Строим дерево категории
*
* @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>';
}
<?php
namespace app\components;
use Yii;
use yii\base\Widget;
use app\models\Category;
class CategoryWidget extends Widget
{
public $tpl;
public $model;
public $data;
public $tree;
public $menuHtml;
public function init()
{
parent::init();
if ($this->tpl === null) {
$this->tpl = 'category';
}
$this->tpl .= '.php';
}
public function run()
{
// get cache
// if ($this->tpl == 'category.php') {
// $menu = Yii::$app->cache->get('category');
// if ($menu) return $menu;
// }
$this->data = Category::find()
->indexBy('id')
->orderBy('sortOrder')
->asArray()
->all();
$this->tree = $this->getTree();
$this->menuHtml = $this->getMenuHtml($this->tree);
// set cache
// if ($this->tpl == 'category.php') {
// Yii::$app->cache->set('category', $this->menuHtml, 60);
// }
return $this->menuHtml;
}
protected function getTree()
{
$tree = [];
foreach ($this->data as $id => &$node) {
if (!$node['parent_id']) {
$tree[$id] = &$node;
} else {
$this->data[$node['parent_id']]['children'][$node['id']] = &$node;
}
}
return $tree;
}
protected function getMenuHtml($tree){
$str = '';
foreach ($tree as $category) {
$str .= $this->catToTemplate($category);
}
return $str;
}
protected function catToTemplate($category)
{
ob_start();
include __DIR__ . '/category_tpl/' . $this->tpl;
return ob_get_clean();
}
}
<?= $category['title'] ?>
<?php if (isset($category['children'])): ?><br/>
<?= $this->getMenuHtml($category['children']) ?>
<?php endif; ?>
<?= CategoryWidget::widget(['tpl' => 'category']) ?>