我正在使用原始文本查询来生成结果。但是为了避免 sql 注入,它希望对传入 userStat() 函数的变量(即 $from 和 $to)进行参数化查询。
puclic function userStat($from, $to){
$sql = "select u.user_id as ID, u.email as Email
from User u
where u.type = 'x'
and u.join_date BETWEEN '$from' AND '$to'";
$rawData = Yii::app()->db->createCommand($sql);
return $userData = new CSqlDataProvider($rawData, array(
'keyField'=>'ID',
));
}
Run Code Online (Sandbox Code Playgroud)
现在我想用文本查询($sql)绑定 $from 和 $to。
请帮我弄清楚这一点。
我尝试从字符串中删除此符号.我试试这个:
$string = preg_replace('`', '', $string);
Run Code Online (Sandbox Code Playgroud)
但得到:
No ending delemiter ''发现'
我做错了什么?
我试图通过简单的形式上传文件,然后将其发布到我的控制器并将其移动到服务器中的某个目录,但该文件未被发布,这是我的代码:
<form id="loginForm" method="post" class="form-horizontal" style="display: none;" action="<?php echo Yii::app()->createUrl('jobs/view', array('id'=>$model->idJob)); ?>">
<div class="form-group">
<label class="col-md-3 control-label">Full Name</label>
<div class="col-md-5">
<input type="text" class="form-control" name="fullName" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Email</label>
<div class="col-md-5">
<input type="email" class="form-control" name="email" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Phone Number</label>
<div class="col-md-5">
<input type="text" class="form-control" name="phoneNumber" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Upload your CV</label>
<div class="col-md-5">
<input type="file" class="form-control" name="cv" id="cv" />
</div>
</div>
<div class="form-group">
<div class="col-md-5 col-md-offset-3">
<button type="submit" …Run Code Online (Sandbox Code Playgroud) 当我需要更新时,我会收到这个答案.我该做什么?
public function actionUpdate($id)
{
if(isset($_POST['submit']))
{
$recruit = Recruit::model()->findByPk($_POST['pid']);
$recruit->title = $_POST['title'];
$test->save();
$this->redirect(array('admin','id'=>$id));
}
$this->render('update',array(
'model'=>$this->loadModel($_POST['pid']),
'id'=>$id,
'pid'=>$_POST['pid'],
));
}
Run Code Online (Sandbox Code Playgroud) 它的控制器文件
class NameFormController extends Controlle
{
public function actionCreate()
{
$model = new NameForm;
if(isset($_POST['NameForm']))
{
$model->attributes=$_POST['NameForm'];
$model->save();
}
$this->render('index' ,array('model'=> $model));
}
}
Run Code Online (Sandbox Code Playgroud)
它的模块文件
class NameForm extends CActiveRecord
{
public $name;
public function tableName()
{
return 'name' ;
}
public function rules()
{
return array('name','required');
}
public function attributeLabels()
{
return array
('id'=>'ID',
'name'=>'Name'
);
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Run Code Online (Sandbox Code Playgroud)