Jump to content
Larry Ullman's Book Forums

ronallensmith

Members
  • Content Count

    28
  • Joined

  • Last visited

  • Days Won

    2

ronallensmith last won the day on September 22 2013

ronallensmith had the most liked content!

Community Reputation

3 Neutral

About ronallensmith

  • Rank
    Member
  1. Looks like that's the one!! Yea!! I was actually using Yii::app()->user->name == 'admin' about a week ago, but it didn't work because I didn't kow the correct syntax, and it was erroring out so I abandoned it. The key was the "", the === and the ternary. I can't find this anywhere I was looking. Thanks Edward. Here's the whole thing as intended: array( 'class'=>'CButtonColumn', 'buttons'=>array ( 'delete'=>array (
  2. I played around with this for some time and couldn't get it to work properly. It removes "Delete" button for both authenticated users: array( 'class'=>'CButtonColumn', 'buttons'=>array ( 'delete'=>array ( 'visible'=>"(Yii::app()->user->checkAccess('demo')) ? true : false;", ) ) ), My access rules are: public function acc
  3. The full code for admin.php is: <?php /* @var $this TblContactsController */ /* @var $model TblContacts */ $this->breadcrumbs=array( 'Tbl Contacts'=>array('index'), 'Manage', ); $this->menu=array( array('label'=>'List TblContacts', 'url'=>array('index')), array('label'=>'Create TblContacts', 'url'=>array('create')), ); Yii::app()->clientScript->registerScript('search', " $('.search-button').click(function(){ $('.search-form').toggle(); return false; }); $('.search-form form').submit(function(){ $('#tbl-contacts-grid').yiiGridView
  4. Thanks Larry, The error follows below and was generated when using the code mentioned in post# 14 above: # /protected/views/MyModel/admin.php array( 'class'=>'CButtonColumn', 'buttons'=>array ( 'delete' => array ( 'label'=>'Delete', //other params 'visible'=>!Yii::app()->user->checkAccess('admin'), ), ), ), ), )); ?> The complete error is: PHP warningcall_user_func_array() expect
  5. Hmm, based on http://stackoverflow...l-delete-button and http://www.yiiframework.com/doc/api/CButtonColumn, I used # /protected/views/MyModel/admin.php array( 'class'=>'CButtonColumn', 'buttons'=>array ( 'delete'=>array ( 'label'=>'Delete', 'visible'=>!Yii::app()->user->checkAccess('guest'), ), ), ), B
  6. Thanks Edward and Larry. Sorry I stepped away from the problem for a day to handle other issues. I'm taking a look at your response Edward; give me a liitle time to give any feedback. Hey, Larry! I've gotten better at knowing where to look regarding solving Yii related problems, and in my opinion the Yii Book and the Yii framework Class Reference docs have yielded the most frequent hints and solutions. Thanks I'm very gratefull for your help.
  7. Thanks Edward, I reeeaaallly appreciate your help. Concerning your first suggestion "...just direct admin or the user to the same CGridView..." When you say "...just disable its attributes depending on the user.", are you meaning to do so in /protected/controllers/MyModelController.php, public function accessRules(), or somewhere else?? Here's where I'd like to have users, other than admin, only have the "View" button displayed; all 3 default buttons displayed for admin, of course. I took a look around and can't find anything on how to do this using just one "CGridView"--unless I'm overloo
  8. The following seems to work for redirecting to two different views based on identity of user, but I'd like someone to check it's validity and best practices, since I'm a newbie: # protected/controllers/SiteController.php public function actionLogin() { $model=new LoginForm; // if it is ajax validation request if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if(isset($_POST['LoginForm']))
  9. SOLVED: KonApaz in the Yii Framework Forum suggested: #/protected/controllers/SiteController::actionLogin() $this->redirect(Yii::app()->user->returnUrl=array('controller/action')); This works beautifully, unless someone has a better (best practices) way.
  10. In the Yii Book in the section "Handling Redirections" it talks about $this->redirect(Yii::app()->user->returnUrl);. However, in my opinion, for the beginner, there could be more info on how to redirect to a different page/view upon a successful login. In my case I need to redirect to /protected/views/myModel/admin.php. This was completely skipped over in the material. What would I replace Yii::app()->user->returnUrl with in my case??
  11. I just had a thought while researching the above. Could it be that, using the code you suggest above, I just copy and rename the .../protected/views/MyModel/admin.php file to something like '.../protected/views/MyModel/guest.php' in order to make the second view for the 'guest' user? Then edit the 'CButtonColumn' Class in guest.php to remove the 'update' and 'delete' buttons?
  12. Thanks Edward, Do I create the two separate views with the Gii tool; when I went to do that it looked like a totally separate Controller would be created? And, this is a very simple site where I only have the 2 users 'admin' and 'guest'. So, will the 'Yii::app()->user->type === ...' work with the following: class UserIdentity extends CUserIdentity { /** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persis
  13. I'm looking through the book, but getting turned around on the concept of redirecting authenticated users to custom views. Is it that I create another Model and Controller with the Gii tool to create a custom view, or can that be done using the existing Model's Controller?? I'm using the following Access Rules: public function accessRules() { return array( array('deny', // deny guest to perform 'create', 'update' and 'delete' actions 'actions'=>array('create','update','delete'), 'users'=>array('guest'), ),
  14. I'm adding a heads-up here! When I uploaded my app, the math on the time changed because the hosting server was in a different timezone. So... Arghh!! I commented-out the 'public function behaviors()' code and changed the 'public function beforeSave()' code to: // added to INSERT "endTime" and "duration" public function beforeSave() { if ($this->isNewRecord) { $this->endTime = date('Y-m-d H:i:s', strtotime('-2 Hours')); // set the endTime $start = new DateTime($this->startTime); $en
  15. A hearty thanks to you Edward for the leads you gave in working on this solution, and if you or Larry have a better more concise/cleaner way of doing the same thing, or a way the same thing could have been done using the Yii classes, please let me know.
×
×
  • Create New...