EmailArchive表:
id email_id to from
1 101 uk msm
2 102 uu avc
3 101 rk uk
4 103 xyz abc
5 104 xyz poi
6 104 abc xyz
7 101 xyz abc
Run Code Online (Sandbox Code Playgroud)
现在在Yii我想要记录,其中email_id = 101我正在使用下面的代码,但它不起作用.
$id =101;
$criteria = new CDbCriteria();
$criteria->addCondition("email_id < :email_id");
$comments = EmailArchive::model()->findAll($criteria, array(':email_id' => $id,));
Run Code Online (Sandbox Code Playgroud) 是否可以在Yii中的ActiveRecord中进行子查询?
我有这样的查询:
select * from table1
where table1.field1 in (select table2.field2 from table2)
我目前正在使用以下代码:
object1::model()->findAll(array('condition'=>'t.field1 in (select table2.field2 from table2)'))
[编辑]
我想知道是否有一种方法来构造子查询而不使用SQL,并且不使用连接.
有什么解决方案吗?
并提前感谢.
YII中ActiveRecord和模型之间的关系或区别是什么?
我试图登录is_object(CActiveRecord::model('Project'));并期待false但它又回来了true;
由于日志记录表明它是一个对象,我认为它代表表中的一行,但我找不到任何代表coloumns的属性.
另外http://www.yiiframework.com/doc/api/1.1/CActiveRecord#model-detail声明它返回了一个CActiveRecord类的实例,但我找不到该对象中表行的任何值.
Yii中使用$condition和$paramin的说明findByAttributes
在大多数情况下,这就是我使用的方式 findByAttributes
Person::model()->findByAttributes(array('first_name'=>$firstName,'last_name'=>$lastName));
Run Code Online (Sandbox Code Playgroud) 此验证行不起作用.我可以上传任何尺寸的图像.
['image', 'image', 'minWidth' => 250, 'maxWidth' => 250,'minHeight' => 250, 'maxHeight' => 250],
Run Code Online (Sandbox Code Playgroud)
在控制器中,我使用.
$image = UploadedFile::getInstance($this, 'image');
Run Code Online (Sandbox Code Playgroud) 在yii中,我使用安全问题创建密码重置功能.首先,用户需要输入他的电子邮件ID.我在创建emailform.php views->User1作为
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'email-form',
'enableClientValidation'=>true,
));
echo CHtml::textField('email');
echo CHtml::submitButton('Send');
$this->endWidget();
Run Code Online (Sandbox Code Playgroud)
在控制器中我创建了方法as
public function actionPassword() {
if (isset($_POST['email'])) {
$email = $_POST['email'];
//process email....
//....
}
$this->render('_emailForm');
}
Run Code Online (Sandbox Code Playgroud)
现在我想检查User表中是否存在此电子邮件ID.如果确实如此,那么我想向他展示一个安全问题.我该如何实现呢?
我现在仍然在博客教程上学习YII,并对一些代码感到好奇.
在此链接
http://www.yiiframework.com/doc/blog/1.1/en/prototype.auth
有这样的代码
<?php
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$username=strtolower($this->username);
$user=User::model()->find('LOWER(username)=?',array($username));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$user->validatePassword($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->id;
$this->username=$user->username;
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
}
public function getId()
{
return $this->_id;
}
}
Run Code Online (Sandbox Code Playgroud)
我对一些代码很好奇.
?>代码的最后一行没有?$user=User::model()->find('LOWER(username)=?',array($username));为什么用LOWER(username)=?不LOWER(username)=.为什么有需要?,是否有一些查询有条件我可能还不知道呢?在尝试与yii框架中的mysql连接时,它显示
"CDbConnection无法打开数据库连接:找不到驱动程序"错误
php代码:
'db'=>array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost:3306;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
),
Run Code Online (Sandbox Code Playgroud)
我的PHP驱动程序已经启用,但它显示相同的错误
我正在使用zend studio,zend服务器
我怎么能解决这个问题?