无效的参数号.参数未定义

编程入门 行业动态 更新时间:2024-10-24 18:23:32
本文介绍了无效的参数号.参数未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

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

发布评论

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

>www.elefans.com

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