onunix

onunix

aaaa

  • 财富值1145
  • 威望值0
  • 总积分1145

个人信息

  • 我前面的打印语句写错了:Yii::trace('userid is ',$userId); 。错误地写成,了,实际userid是有值的,我看了下,它的值竟然是username,就错在这里了。问题就出在这里了,应该是userid的,怎么值会变成username了。

    $userId应该为1,不应该为admin。

    我看了下mainl.php

    'srbac' => array(
    'userclass'=>'User', //default: User
    'userid'=>'user_ID', //default: userid
    'username'=>'username', //default:username
    

    似乎也没有错,错在哪里呢?

  • userid的获取是在哪个文件里面呢?

  • 我加的打印语句:Yii::trace('userid is ',$userId);应该没有错吧,就应该这样打印吧,但是日志中没有打印出来userid。

  • 定位出是因为userid为空,
    我打印出的:

    2012/06/06 16:01:22 [trace] [admin] userid is 
    in D:\skill\finance\Yii\protected\modules\srbac\components\SDbAuthManager.php (32)
    in D:\skill\finance\Yii\protected\modules\srbac\controllers\SBaseController.php (84)
    in D:\skill\finance\Yii\index.php (13)
    2012/06/06 16:01:22 [trace] [system.db.CDbCommand] Querying SQL: SELECT name, type, description, t1.bizrule, t1.data, t2.bizrule AS bizrule2, t2.data AS data2 FROM items t1, assignments t2 WHERE name=itemname AND userid=:userid
    in D:\skill\finance\Yii\protected\modules\srbac\components\SDbAuthManager.php (35)
    

    userid为什么为空呢?它应该是在哪里赋值的呢?

    class SDbAuthManager extends CDbAuthManager {
    
      /**
       * Performs access check for the specified user.
       * @param string the name of the operation that need access check
       * @param mixed the user ID. This should can be either an integer and a string representing
       * the unique identifier of a user. See {@link IWebUser::getId}.
       * @param array name-value pairs that would be passed to biz rules associated
       * with the tasks and roles assigned to the user.
       * @return boolean whether the operations can be performed by the user.
       */
      public function checkAccess($itemName, $userId, $params=array()) {
        if (!empty($this->defaultRoles) && in_array($itemName,$this->defaultRoles)) {
          return true;
        }
        
        $sql = "SELECT name, type, description, t1.bizrule, t1.data, t2.bizrule AS bizrule2, t2.data AS data2 FROM {$this->itemTable} t1, {$this->assignmentTable} t2 WHERE name=itemname AND userid=:userid";
        $command = $this->db->createCommand($sql);
        $command->bindValue(':userid', $userId);
        Yii::trace('userid is ',$userId);
        // check directly assigned items
        $names = array();
        foreach ($command->queryAll() as $row) {
           Yii::trace('Checking permission "' . $row['name'] . '"', 'system.web.auth.CDbAuthManager');
          if ($this->executeBizRule($row['bizrule2'], $params, unserialize($row['data2']))
            && $this->executeBizRule($row['bizrule'], $params, unserialize($row['data']))) {
            if (strtolower($row['name']) === strtolower($itemName)) {
              return true;
            }
            $names[] = $row['name'];
          }
        }
    
  • 似乎是我哪个地方做得不对,按照你的在SBaseController中添加public $menu=array();
    又出了个新的错,怎么可能出这么多错呢?

    CException
    属性 "AbcController.breadcrumbs" 未被定义.

    D:\skill\finance\Yii\protected\views\Abc\admin.php(2)
    
    01 <?php
    02 $this->breadcrumbs=array(
    03     'Abcs'=>array('index'),
    04     'Manage',
    05 );
    06 
    07 $this->menu=array(
    08     array('label'=>'List Abc', 'url'=>array('index')),
    09     array('label'=>'Create Abc', 'url'=>array('create')),
    10 );
    11 
    12 Yii::app()->clientScript->registerScript('search', "
    13 $('.search-button').click(function(){
    14     $('.search-form').toggle();
    
  • 自动生成的代码,怎么会有问题呢?要手动修改?那怎么修改呢

  • 发布了话题
    请问自动建立授权项在哪里
  • 应该去掉其中的 !号,改为

    if($model->hasAttribute('During'))
    {
        .....
    }
    

    就OK 了,只要数据库表中有这个During字段,就会用During去过滤。没有During字段,也不会出问题。 我要的就是这种效果。

  • 发布了话题
    请教srbac使用过程中的问题
  • 没有起效,为什么没有起效呢?每次 isset($model->During) 都是返回 false,即 $model->During=date('Y-m-01',strtotime('-5 month'))没有执行,这是为什么呢?
    我的controller

    public function actionAdmin()
    {
        $model=new Test('search');
        $model->unsetAttributes();  // clear any default values
    		
        if(isset($model->During))
            $model->During=date('Y-m-01',strtotime('-5 month'));
    		
        if(isset($_GET['Test']))
            $model->attributes=$_GET['Test'];
    
        $this->render('admin',array(
            'model'=>$model,
        ));
    }
    

    我的model

    <?php
    
    /**
     * This is the model class for table "Test".
     *
     * The followings are the available columns in table 'Test':
     * @property integer $a
     * @property string $depOrProfitName
     * @property string $During
     */
    class Test extends CActiveRecord
    {
    	/**
    	 * Returns the static model of the specified AR class.
    	 * @param string $className active record class name.
    	 * @return Test the static model class
    	 */
    	public static function model($className=__CLASS__)
    	{
    		return parent::model($className);
    	}
    
    	/**
    	 * @return string the associated database table name
    	 */
    	public function tableName()
    	{
    		return 'Test';
    	}
    
    	/**
    	 * @return array validation rules for model attributes.
    	 */
    	public function rules()
    	{
    		// NOTE: you should only define rules for those attributes that
    		// will receive user inputs.
    		return array(
    			array('depOrProfitName', 'length', 'max'=>500),
    			array('During', 'safe'),
    			// The following rule is used by search().
    			// Please remove those attributes that should not be searched.
    			array('a, depOrProfitName, During', 'safe', 'on'=>'search'),
    		);
    	}
    
    	/**
    	 * @return array relational rules.
    	 */
    	public function relations()
    	{
    		// NOTE: you may need to adjust the relation name and the related
    		// class name for the relations automatically generated below.
    		return array(
    		);
    	}
    
    	/**
    	 * @return array customized attribute labels (name=>label)
    	 */
    	public function attributeLabels()
    	{
    		return array(
    			'a' => 'A',
    			'depOrProfitName' => 'Dep Or Profit Name',
    			'During' => 'During',
    		);
    	}
    
    	/**
    	 * Retrieves a list of models based on the current search/filter conditions.
    	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
    	 */
    	public function search()
    	{
    		// Warning: Please modify the following code to remove attributes that
    		// should not be searched.
    
    		$criteria=new CDbCriteria;
    
    		$criteria->compare('a',$this->a);
    		$criteria->compare('depOrProfitName',$this->depOrProfitName,true);
    		$criteria->compare('During',$this->During,true);
    
     		return new CActiveDataProvider($this, array(
    			'criteria'=>$criteria,
    		));
    	}
    }
    
经理 等级规则
1145/2000
资料完整度
60/100
用户活跃度
0/100

Ta的关注

0

Ta的粉丝

2

Ta的访客

3