问题描述
限时送ChatGPT账号..更新2:
我在/protected/components 中创建了一个新的 WebUser.php 组件,如下所示:
I've created a new WebUser.php component in /protected/components as follows:
<?php
class WebUser extends CWebUser{
private $_model;
function getId(){
$user = $this->loadUser(Yii::app()->user->id);
return $user->id;
}
protected function loadUser($id=null){
if($this->_model===null)
{
if($id!==null)
{
$this->_model=Users::model()->findByPk($id);
}
return $this->_model;
}
}
}
我也在 main.php 中注册了组件.上传更改后,我的应用程序仍然指出未定义 WebUser.getId.
I've registered the component in main.php as well. After uploading changes, my app still states that WebUser.getId is not defined.
更新:
进行更改然后回滚后,我收到一个新错误:
UPDATE:
After making changes and then rolling them back, I'm getting a new error:
Property "CWebUser.getId" is not defined.
有问题的代码片段是:
$user = Users::model()->find('username=?', array(
Yii::app()->user->getId));
应该如何以及在何处设置 getId 以引用用户模型中的 $id 字段?
How and where should getId be set to reference the $id field in the Users model?
我的 UserController 抛出以下 SQL 错误:
My UserController is throwing the following SQL Error:
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number:
parameter was not defined. The SQL statement executed was: SELECT * FROM `users` `t` WHERE
username=? LIMIT 1
错误是由控制器的这个片段引起的:
The error is being caused by this snippet of the controller:
public function actionProfile($id=''){
$user = Users::model()->find('username=?', array(Yii::app()->user->getId()));
if(!$id){
$id = $user->id;
if(!$id)
$this->redirect('login');
}
if( getUserSess('user_type') == 'Sitter') {
$this->render('profile_detail', array('user_id' => $id ));
} else {
$this->render('petowner_profile_detail',array(
'model'=>$this->loadModel($id),
));
}
}
profile_detail 视图如下:
The profile_detail view is as follows:
<?php
if(!$user_id){
$user_id = getUserSess('id');
}
$this->widget('ext.UserProfile.BasicProfile',array('user_id'=>$user_id)); ?>
<?php //$this->widget('ext.UserProfile.UserServices',array('user_id'=>$user_id)); ?>
petowner_profile_detail 视图如下:
The petowner_profile_detail view is as follows:
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'username',
'email',
'phone',
'fname',
'lname',
'address1',
'address2',
'city',
'state',
'zip',
'is_year_old',
'user_type',
// 'register_date',
// 'varified_date',
// 'is_premium',
// 'last_login',
),
)); ?>
我如何纠正他的 SQL 错误?
How do I rectify he SQL error?
推荐答案
更新:
$user = Users::model()->find('username=:id', array(":id" => Yii::app()->user->id));
$user = Users::model()->find('username=:id', array(":id" => Yii::app()->user->id));
更新2:
Yii::app()->user->getId() 或 Yii::app()->user->id 不是 Yii::app()->user->getId
Yii::app()->user->getId() or Yii::app()->user->id not Yii::app()->user->getId
这篇关于无效的参数号.参数未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论