2013-05-29 4 views
0

내 작업에 필요한 YII 프레임 워크에 대한 새로운 내용이며 사용자/관리자, UserController 및 User (모델) 뷰가 있지만이 오류가 계속 발생합니다. 혼란 .. 나는YII 정의되지 않음 변수

PHP notice 
Undefined variable: users 

C:\xampp\htdocs\winegmobile\protected\controllers\UserController.php(147) 

135  */ 
136  public function actionAdmin() 
    137  { 
138   $model=new User('search'); 
139   $model->unsetAttributes(); // clear any default values 
140   if(isset($_GET['User'])) 
141    $model->attributes=$_GET['User']; 
142 
143   $this->render('admin',array(
144    'model'=>$model, 
145      
146       'User'=>$User 
147  )); 
148  } 
149 
150  /** 
151  * Returns the data model based on the primary key given in the GET variable. 
152  * If the data model is not found, an HTTP exception will be raised. 
153  * @param integer $id the ID of the model to be loaded 
154  * @return User the loaded model 
155  * @throws CHttpException 
156  */ 
157  public function loadModel($id) 
158  { 
159   $model=User::model()->findByPk($id); 


     This is the view/User/admin 
    <?php 
    /* @var $this UserController */ 
    /* @var $model User */ 

    $this->breadcrumbs=array(
'Users'=>array('index'), 
'Manage', 
    ); 

    $this->menu=array(
array('label'=>'List User', 'url'=>array('index')), 
array('label'=>'Create User', 'url'=>array('create')), 
    ); 

    Yii::app()->clientScript->registerScript('search', " 
    $('.search-button').click(function(){ 
$('.search-form').toggle(); 
return false; 
    }); 
    $('.search-form form').submit(function(){ 
$('#user-grid').yiiGridView('update', { 
    data: $(this).serialize() 
}); 
return false; 
    }); 
    "); 
    ?> 

    <h1>Manage Users</h1> 
    <?php $this->widget('bootstrap.widgets.TbBreadcrumbs', array(
    'links'=>array('Admin'=>'index.php?r=site/admin', 'User'))); ?> 
    <p> 
    You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt; 
    </b>, 
    <b>&gt;=</b>, <b>&lt;&gt;</b> 
    or <b>=</b>) at the beginning of each of your search values to specify how the 
    comparison 
    should be done. 
    </p> 

    <?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?> 
    <div class="search-form" style="display:none"> 
    <?php $this->renderPartial('_search',array(
'model'=>$model, 

    'User'=>$User, 

    )); ?> 
    </div><!-- search-form --> 

    <?php 
    //change starts here 

    $this->widget('bootstrap.widgets.TbGridView', array(
'type'=>'striped bordered condensed', 
'dataProvider'=>$model->search(), 
'filter'=>$model, 
'template'=>"{items}\n{pager}", 
'columns'=>array(
    array('name'=>'username', 'header'=>'Username'), 
    array('name'=>'FirstName', 'header'=>'First Name'), 
    array('name'=>'LastName', 'header'=>'Last Name'), 
    array('name'=>'Email', 'header'=>'Email'), 
    array('name'=>'password', 'header'=>'Password'), 
    array(
     'class'=>'bootstrap.widgets.TbButtonColumn', 
     'htmlOptions'=>array('style'=>'width: 50px'), 
    ),  
    ), 
    )); 






    //end 







    //$this->widget('zii.widgets.grid.CGridView', array(
//'id'=>'user-grid', 
//'dataProvider'=>$model->search(), 
//'filter'=>$model, 
//'columns'=>array(
    //'id', 
// 'FirstName', 
// 'LastName', 
// 'Email', 
// 'Password', 
// 'address_id', 
// array(
    // 'class'=>'CButtonColumn', 
    //), 
//), 
//)); 

.. 누군가가 여기 좀 도와 수 있던 UserController 여기

<?php 
    /* @var $this UserController */ 
    /* @var $model User */ 

$this->breadcrumbs=array(
'Users'=>array('index'), 
'Manage', 
); 

    $this->menu=array(
array('label'=>'List User', 'url'=>array('index')), 
array('label'=>'Create User', 'url'=>array('create')), 
); 

    Yii::app()->clientScript->registerScript('search', " 
    $('.search-button').click(function(){ 
$('.search-form').toggle(); 
return false; 
    }); 
    $('.search-form form').submit(function(){ 
$('#user-grid').yiiGridView('update', { 
    data: $(this).serialize() 
}); 
return false; 
    }); 
    "); 
     ?> 

     <h1>Manage Users</h1> 
    <?php $this->widget('bootstrap.widgets.TbBreadcrumbs', array(
    'links'=>array('Admin'=>'index.php?r=site/admin', 'User'))); ?> 
    <p> 




     <b>&gt;=</b>, <b>&lt;&gt;</b>or <b>=</b>) at the beginning of each of your search 
     values to specify how the comparison should be done. 
    </p> 

    <?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?> 
    <div class="search-form" style="display:none"> 
    <?php $this->renderPartial('_search',array(
'model'=>$model, 


    )); ?> 
    </div><!-- search-form --> 

    <?php 
    //change starts here 

     $this->widget('bootstrap.widgets.TbGridView', array(
     'type'=>'striped bordered condensed', 
    'dataProvider'=>$model->search(), 
    'filter'=>$model, 
    'template'=>"{items}\n{pager}", 
    'columns'=>array(
     array('name'=>'username', 'header'=>'Username'), 
     array('name'=>'FirstName', 'header'=>'First Name'), 
     array('name'=>'LastName', 'header'=>'Last Name'), 
     array('name'=>'Email', 'header'=>'Email'), 
     array('name'=>'password', 'header'=>'Password'), 
     array(
     'class'=>'bootstrap.widgets.TbButtonColumn', 
     'htmlOptions'=>array('style'=>'width: 50px'), 
     ),  
    ), 
    )); 






    //end 







//$this->widget('zii.widgets.grid.CGridView', array(
//'id'=>'user-grid', 
//'dataProvider'=>$model->search(), 
//'filter'=>$model, 
//'columns'=>array(
    //'id', 
// 'FirstName', 
// 'LastName', 
// 'Email', 
// 'Password', 
// 'address_id', 
// array(
    // 'class'=>'CButtonColumn', 
    //), 
//), 
//)); 







?> 

답변

1

호핑 오전 :

public function actionAdmin() { 
    $model = new User('search'); 
    $model->unsetAttributes(); // clear any default values 
    if (isset($_GET['User'])) 
    $model->attributes = $_GET['User']; 

    $this->render('admin', array(
    'model' => $model, 
    'User' => $User // <------ UNDEFINED 
    )); 
} 

$ 사용자는이 방법의 범위에서 정의되지 않습니다. 이 데이터베이스 객체가 있다면

, 당신은 액티브로 검색해야합니다 :

MyTable::model()->findByPk($theUSerId) 

또는 이에 해당.

앱 사용자 인 경우 : Yii::app()->user 트릭을 수행합니다.

$model = new User('search'); 

그것은 당신이 당신 앞으로 전망이 $ 사용자 변수로 무슨 일을하는지에 따라 달라집니다

가능성, 당신은 이미 $ 모델로 있습니다. 강조 텍스트

+0

왜 내가 잘못했는지 알게 됐어. 컨트롤러 오류 메시지에서 'load_model'을 unkluded하고 코드의 오류를 보여 주었다. 나는 ' 비밀 번호 '와 thhat 모든 걸 고정 .. 비록 내가 왜 그 오류가 조금 다른지 이해가 안 돼요 – Megan