YII CActiveRecord

编程入门 行业动态 更新时间:2024-10-24 08:29:25
本文介绍了YII CActiveRecord->find()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我现在还在博客教程上学习 YII 并且对一些代码感到好奇.

Im now still learning YII on blog tutorial and curious with some code.

在这个链接上
http://www.yiiframework/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;
}
}

我对一些代码很好奇.

为什么代码的最后一行没有?>?在这一行 $user=User::model()->find('LOWER(username)=?',array($username)); 为什么使用 LOWER(username)=? 不是 LOWER(username)=.为什么需要?,这是一些我还不知道的查询条件吗? Why there is no ?> at the end line of the code? at this line $user=User::model()->find('LOWER(username)=?',array($username)); why using LOWER(username)=? not LOWER(username)=. WHy there is need ?, is this some query conditional that i didn't know yet maybe?

推荐答案

?> 根据 此链接:

文件末尾的 PHP 块的结束标记是可选的,在某些情况下省略它在使用 include() 或 require() 时很有帮助,因此文件末尾不会出现不需要的空格,并且稍后您仍然可以向响应添加标头.如果您使用输出缓冲,并且不希望在包含文件生成的部分末尾添加不需要的空格,这也很方便.

The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

? 与 SQL 语法相关,从 此处.另外这里的第二个答案说:

the ? is related to SQL syntax as seen from here. Also the second answer here says that:

问号代表稍后将被替换的参数.使用参数化查询比将参数直接嵌入到查询中更安全.

The question mark represents a parameter that will later be replaced. Using parameterized queries is more secure than embedding the parameters right into the query.

这篇关于YII CActiveRecord->find()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:53:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047576.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:YII   CActiveRecord

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!