public function getSemilarProducts()
{
if(($models = Products::find()->where(['in', 'id_genre', [1,4,5])->andWhere(['in', 'id_tags', [2,6,5])->limit(5)->all()) !== null){
return $models;
}
else{
throw new NotFoundHttpException('The requested page does not exist.');
}
}
$url = Utl::toRoute(// путь к Вашему контролеру/действию.);
$this->registerJs(
"
$('.month').click(function() {
var date = $(this).text();
$.ajax({
url: '".$url."',
date: date,
method: 'post',
dataType: 'json',
success: function () {
alert('success');
},
error: function (response) {
console.log(response);
}
})
});
", yii\web\View::POS_END)
Html::a('Link', $url, ['data' => ['ajaxurl' => Url::toRoute(// путь к контролеру/действию)]])
$('a').on('click', function(){
var url = $(this).attr('data-ajaxurl')
$.ajax({
url: url
})
})
public function actionIndex()
{
if(Yii::$app->request->isAjax){
if(Yii::$app->request->post('myParam') == 1){
$param = 'Ответ сервера - ' . Yii::$app->request->post('myParam');
}
else{
$param = 'Ответ сервера - ' . Yii::$app->request->post('myParam');
}
return $this->asJson($param);
}
return $this->render('index');
}
<?php
$form = ActiveForm::begin([
'id' => 'form1',
'action' => Url::to(['images/index']),
'options' => [
'data-pjax' => 'pjax1'
]
]);
echo Html::submitButton('Добавить', ['data' => ['param' => 1]]);
echo Html::hiddenInput('myParam', false);
echo Html::submitButton('Заменить', ['data' => ['param' => 0]]);
ActiveForm::end();
?>
<div id="result"></div>
<?php
$this->registerJs("
$('button').on('click', function(e){
e.preventDefault();
var url = $(this).closest('form').attr('action');
var param = $(this).attr('data-param')
$.ajax({
url: url,
type: 'POST',
data: {myParam: param},
success: function(data){
$('#result').text(data)
}
})
})
")
?>
[
'class' => 'yii\grid\ActionColumn',
'buttons' => [
'view' => function($url, $model, $key){
return Html::a('view',$url . '/car/' . $model->username ); // в общем подставьте свои параметры.
},
'update' => function($url, $model, $key){
// your code
},
'delete' => function($url, $model, $key){
// your code
}
]
]
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {update} {delete} {customButton}',
'buttons' => [
'view' => function($url, $model, $key){
return Html::a('view',$url . '/car/' . $model->username ); // в общем подставьте свои параметры.
},
'update' => function($url, $model, $key){
// your code
},
'delete' => function($url, $model, $key){
// your code
},
'customButton' => function($url, $model, $key){
return Html::a('CustomButton', ['/site/index']); // параметры, конечно же, подставьте свои.
}
]
]
'view' => function($url, $model, $key) use ($your_param){
return Html::a('view',$url . '/car/' . $your_param ); // в общем подставьте свои параметры.
},
'car' => 'base/index' // укажите своё действие вместо index
Menu::widget([
'items' => $items
])
'filterModel' => $searchModel
для всей таблицы.[
'attribute' => 'id_portfolio',
'headerOptions' => ['class' => 'col-md-1'],
'format' => 'text',
'filter' => Portpholio::getAllPortfolio(),
'value' => 'portfolio.title'
],
public static function getAllPortfolio()
{
return ArrayHelper::map(self::find()->orderBy(['name' => SORT_ASC])->all(), 'id', 'name');
}
public $id_portfolio;
$query = Order::find()->with('portfolio');
$query->andFilterWhere('{{%portfolio}}.id' => $this->id_portfolio);
const STATUS_LIVE = 0;
const STATUS_ERROR = 1;
/* и так далее */
public function rules()
{
return [
['status', 'integer'],
['status', 'default', 'value' => self::STATUS_LIVE],
['status', 'in', 'range' => array_keys(self::getStatusesArray())],
];
}
/* метод использовать при выводе статуса в view.php*/
public function getStatusName()
{
return ArrayHelper::getValue(self::statusesArray(), $this->status);
}
public static function getStatusesArray()
{
return [
self::STATUS_LIVE => 'Live',
self::STATUS_ERROR => 'Error',
/* и так далее */
];
}
'filter' => YOUR_MODEL_NAME::getStatusesArray()
$form->field($model, 'status')->dropDownListYOUR_MODEL_NAME::getStatusesArray(), ['prompt' => 'Select'])
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} site.ru$
Rewriterule ^robots.txt$ web/robots.txt [L]
public function actionPostSpecifics(){
if(Yii::$app->request->isAjax){
$model = new Post();
$model->load(Yii::$app->request->post());
$category_id = $model-> category_id;
$form = new \yii\widgets\ActiveForm;
return $this->renderAjax('form_specifics', [
'model' => $model ,
'category_id' => $category_id,
'form' => $form
]);
}
}
echo $form->field($model, 'attribute_name')->textInput();
use yii\bootstrap\ActiveForm;
$form = ActiveForm::begin(['layout' => 'horizontal'])
$arr = [
[
"title"=> "Сайт1",
"link"=> "site1.ru"
],
[
"title"=> " Сайт2",
"link"=> "site2.ru"
],
[
"title"=> "Сайт2",
"link"=> "site3.ru"
]
];
<?= $form->field($model, 'email')->radioList(ArrayHelper::map($arr, 'title', 'link'),[
'item' => function($index, $label, $name, $checked, $value) {
return '<label class="modal-radio" style="display:block;">
<input type="radio" name="' . $name . '" value="' . $value . '" tabindex="3">
<i></i>
<span>' . ucwords($label) . '</span>
</label>';
}
]) ?>
Если просто создать форму с 2 полями field_3, field_4, то злоумышленник зная какие еще есть поля, может отправить и поля field_1, field_2 и они перезапишутся.
if (******** && $form->validate()) {
******
if ($model->save(true)) {
*****
}
}
public boolean save ( $runValidation = true, $attributeNames = null )
<?php
$form = ActiveForm::begin([
'id' => 'appointment_form',
'fieldConfig' => [
'options' => [
'tag' => 'span',
'class' => 'input input--kohana'
],
'template' => '{input}{label}{error}',
'inputOptions' => ['class' => 'input__field input__field--kohana'],
'labelOptions' => [
'class' => 'input__label input__label--kohana',
]
]
]);
?>
<?= $form->field($model, 'name')->textInput()->label("<i class=\"icon-phone5 icon icon--kohana\"></i><span class=\"input__label-content input__label-content--kohana\">" . $model->getAttributeLabel('name') . "</span>") ?>
<!-- ОСТАЛЬНЫЕ ПОЛЯ ФОРМЫ -->
<?= $form->field($model, 'body')->textInput()->label() ?>
<?= Html::submitButton('Submit'); ?>
<?php
ActiveForm::end();
?>
// Удалить!!!
/* $content = "<p>Email: " . $this->email1 . "</p>";
$content .= "<p>Name: " . $this->name1 . "</p>";
$content .= "<p>Phone: " . $this->phone . "</p>";
$content .= "<p>Datepicker: " . $this->datepicker . "</p>";
$content .= "<p>Body: " . $this->body1 . "</p>";*/
if ($this->validate()) {
Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $this])
app\web\themes\name_theme\images
<?= Html::img('@web/themes/name_theme/images/page4_img1.jpg') ?>
@web
class PortfolioAsset extends AssetBundle
{
//public $basePath = '@app/themes/portfolio/assets';
//public $baseUrl = '@app/themes/portfolio';
public $sourcePath = '@app/themes/portfolio/assets';
public $css = [
'css/bootstrap.min.css',
'css/stylish-portfolio.css',
'font-awesome/css/font-awesome.min.css',
'http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,300italic,400italic,700italic'
];
public $js = [
'js/jquery.js',
'js/bootstrap.min.js',
'js/local.js'
];
public $depends = [
];
}
$image = PortfolioAsset::register($this);
echo Html::img($image->baseUrl.'/img/portfolio-1.jpg');
$theme = $this->theme;
public $baseUrl = '@app/themes/portfolio';
и получаете изображение уже таким способомecho Html::img($theme->getUrl('assets/img/portfolio-4.jpg'));