我想使用一个yii2
查询,我想检查一个不等于条件.我试过这样但是没有给出预期的结果.我该怎么做?
$details = MovieShows::find()->where(['movie_id'=>$id])
->andWhere(['location_id'=>$loc_id])
->andWhere(['cancel_date'=>!$date])->all();
Run Code Online (Sandbox Code Playgroud) 我按照这个链接.我的代码在控制器中如下
public function actionFunction4()
{
$this->layout="sintel";
$model= new Customers();
\Yii::$app->getSession()->setFlash('success', 'successfully got on to the payment page');
return $this->render("function4",['model'=>$model]);
}
Run Code Online (Sandbox Code Playgroud)
在视图中
<div id="message">
<?= Yii::$app->session->getFlash('success');?>
</div>
Run Code Online (Sandbox Code Playgroud)
现在我所做的结果并不是我的预期.我收到了一条消息"已成功进入付款页面",就像我已经回复了它一样.如果它与echo类似,那么为什么我们在Yii2中需要一条flash消息.我想我的代码中可能会遗漏一些使我的flash消息看起来像普通消息的东西.
我想根据某些条件删除数据库中的一行.我试过这样的
$fanclub = FanClub::find()->where(['user_id'=>$userid])->
andwhere(['crew_member_id'=>$id])->one();
if($fanclub)
{
$fanclub->delete();
}
Run Code Online (Sandbox Code Playgroud)
这是删除数据库中的行的正确方法吗?
当我点击网格视图中的按钮时,我想弹出一个模态.是否可以使用yii2 gridview?
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'time_zone',
'no_of_users',
'bill_name',
'bill_address',
'names.name',
'bill_state',
'bill_city',
'bill_postal',
'bill_mobile',
['header'=>'Plan Info',
'value'=> function($data)
{
//~ print_r($data);die();
return Html::a(Yii::t('app', ' {modelClass}', [
'modelClass' => 'details',
]), ['userdetails/plans','id'=>$data->id], ['class' => 'btn btn-success ']
);
},
'format' => 'raw'
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Run Code Online (Sandbox Code Playgroud)
在上面的网格视图中,当我点击"详细信息"按钮时,我想要弹出一个模态.
谢谢,
我的模型规则是这样的
public function rules()
{
return [
[['email','password'], 'required'],
[['email'],'unique'],
[['status','role_id','created_by', 'updated_by', 'is_deleted'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['first_name', 'last_name', 'email', 'username','location','address','about_me'], 'string', 'max' => 200],
[['phone'], 'string', 'max' => 100]
];
}
Run Code Online (Sandbox Code Playgroud)
在创建新用户时我需要电子邮件和密码,但在更新期间我只需要用户名.我怎样才能做到这一点?
我想为yii2基本模板创建一个REST API.我按照以下链接.
我创建了一个名为users
的控制台,名为UserController
<?php
namespace app\controllers;
use yii\rest\ActiveController;
class UserController extends ActiveController
{
public $modelClass = 'app\models\User';
}
?>
Run Code Online (Sandbox Code Playgroud)
并在网络上
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
],
],
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '4534',
'parsers' => [
'application/json' => 'yii\web\JsonParser', …
Run Code Online (Sandbox Code Playgroud) 我遇到以下jquery代码的问题
$this->registerJs(
'jQuery(document).ready(function($){
$(".member").on("change",function(){
var id = $(this).attr("id");
// alert(id);
var n = $(this).val();
// alert(n);
$.post("'.\Yii::$app->getUrlManager()->createUrl(['death/stl_set_relation','id'=>'+id'])
.'&name="+id)
});
});'
);
Run Code Online (Sandbox Code Playgroud)
我希望ajax链接是这样的 http://192.168.1.4/~user/church/backend/web/death/stl_set_relation?id=20&name=1
但是我的代码我无法正确传递id的值.我的代码创建的是以下url
http://192.168.1.4/~user/church/backend/web/death/stl_set_relation?id=%2Bid&name=20
Run Code Online (Sandbox Code Playgroud)
我也尝试过这样
$.post("'.\Yii::$app->getUrlManager()->createUrl(['death/stl_set_relation','id'=>'"+id"'])
.'&name="+id)
Run Code Online (Sandbox Code Playgroud)
但它没有给我预期的结果
我怎样才能正确传递id的值?
我想在新用户注册时向管理员发送电子邮件。我想我可以用两种方法来做到这一点。一种方法是使用事件,另一种方法是使用 afterSave。通过使用事件控制器代码
public function actionCreate()
{
$model = new Registeration();
if ($model->load(Yii::$app->request->post()))
{
if($model->save())
{
$model->trigger(Registeration::EVENT_NEW_USER);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Run Code Online (Sandbox Code Playgroud)
型号代码
const EVENT_NEW_USER = 'new-user';
public function init(){
$this->on(self::EVENT_NEW_USER, [$this, 'sendMail']);
}
public function sendMail($event){
// code
}
Run Code Online (Sandbox Code Playgroud)
我可以使用该afterSave
方法做同样的事情
型号代码
public function afterSave($insert)
{
//code
return parent::afterSave($insert);
}
Run Code Online (Sandbox Code Playgroud)
那么这两种方法有什么区别吗?Events
使用或哪个更好afterSave()
?
以下是详细视图小部件
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'name',
'entity_name',
'voucher_category',
'credit',
'debit',
'remarks:ntext',
'posting_date',
'payment.method',
[
'label' => 'Reference Date',
'value' => $model->reference_date !=NULL ? $model->reference_date: 'Not Defined',
],
'voucher_no',
],
]) ?>
Run Code Online (Sandbox Code Playgroud)
我想要的是检查
if($model->voucher_category ==0)
{
return "Income Voucher";
}
elseif($model->voucher_category ==1)
{
return "Exepense Voucher";
}
else
{
return "General Voucher";
}
Run Code Online (Sandbox Code Playgroud)
即,我想检查一个条件,根据该条件应该在视图中显示一个值.我如何在详细视图小部件中执行此操作?
我有这样的网格视图
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'movie.movie_name',
'start_date',
'end_date',
'theatre.theatre_name',
'screen.screen_name',
'time.start_time',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Run Code Online (Sandbox Code Playgroud)
我怎样才能按照降序排列start_date
?