Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by ronallensmith

  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.
  16. SOLVED: The following was added to myModel.php // added to INSERT (endTime - startTime) into "duration" public function beforeSave() { if ($this->isNewRecord) { $start = new DateTime($this->startTime); $end = new DateTime(); $endMinus7 = $end->sub(new DateInterval('PT7H')); // correct for 7-hour time difference $dateIntervalObj = $endMinus7->diff($start); // compute the difference in times $this->duration = $dateIntervalObj->format('%H%I%S'); } return parent::beforeSave(); }
  17. I Just tested the following: // added to INSERT (endTime - startTime) into "duration" public function beforeSave() { if ($this->isNewRecord) { $start = new DateTime($this->startTime); $end = new DateTime(); $dateIntervalObj = $end->diff($start); $this->duration = $dateIntervalObj->format('%H%I%S'); } return parent::beforeSave(); } which yielded the follwing two records on two tests: View TblContacts #210 ID 210 Contact Type Inbound Voice-Messag
  18. Thanks Edward, I took a look at the way the table itself is constructed and went at the problem from the "MySQL command-line" standpoint and discovered I could not manually INSERT the time difference into the "duration" field with: SELECT TIMEDIFF('2013-09-20 13:17:20','2013-09-20 13:08:48'); UPDATE tblcontacts SET duration = '00:08:32' where id = 204; as an example. But, this was only happening for some of the records and not others. So, when I looked at that issue, I noticed for some records, "duration" was NULL after the INSERT--displaying as "Not set" in Yii. All the record
  19. Thanks again, The reason for INSERTing the "duration" is because I'll be giving others the ability to login to the site and check the saved records. One item of interest will be "duration"--the time it took for me to complete a task. I'll continue to hammer on the DateTime interval object, but I'll check the others you mentioned.
  20. Thanks for taking the time Edward, I;m now using: // added to INSERT (endTime - startTime) into "duration" public function beforeSave() { if ($this->isNewRecord) { $start = new DateTime($this->startTime); $end = new DateTime(); $diffObj = $end->diff($start); $this->duration = $diffObj->format('%H%I%S'); } return parent::beforeSave(); } and getting: Start Time 2013-09-18 17:31:48 End Time 2013-09-18 17:32:08 Duration
  21. Edward, Your suggestion to revisit using 'beforeSave()' worked also. It's funny because I saw both these approached in the Yii book--DOH! but I went with 'afterSave()' instead. I was all over the web too with this problem. After a while I just got snowed under by an avalanche of info and samples. ...takes fresh eyes some times. Now, I need to replace CDbExpression() with whatever can do (endTime - startTime) and INSERT into "duration". // added to INSERT (endTime - startTime) into "duration, if possible" public function beforeSave() { if ($this->isNewRecord) {
  22. Thanks again. I'll try beforeSave() as well. My table structure as far as "duration" is concerned is: tblcontacts | CREATE TABLE `tblcontacts` ( `id` int(10) unsigned NOT NULL AUTO_INCREM `contactType` enum('Inbound Voice-Message' `startTime` datetime NOT NULL, `endTime` datetime DEFAULT NULL, `duration` datetime NOT NULL,
  23. Thanks Edward, the following worked: array('duration', 'default', 'value'=>new CDbExpression('NOW()'), 'on'=>'insert'), The NOW() call is just a simple test to see if the insert works at all. Now I'll replace that with the math expression that subtracts "startTime" from "endTime"--see above posts marked "SOLVED:". I'm thinking of using MySQL's TIMEDIFF() for the math unless you have a better suggestion using a Yii class. The 'afterSave()' example you gave still did not work and if memory serves me well I tried that one before myself, with the same result--nill. Thanks a bunch
  24. Hi Larry, Sure. My app keeps track of what was said during phone calls. It tracks the time the call started and the time it ended. However I'm stuck on how to INSERT the duration of the call. I've worked out the start and end times--shown above, but don't quite know how to implement the afterSave(). I see a few examples, but it seems I'm not experienced enough with Yii yet to put it all together properly. The following code does not produce errors, but it doesn't INSERT the correct values either. I just get 0000-00-00 00:00:00 in the "duration" column. // added to ...protected
  25. Thanks for the reply Larry, As you can see, I've solved 66% of my problem. Now I need to insert the difference between the above two timestamps into a field called 'duration' in H:i:s format. I've looked all over the Yii docs and the Forum where I came upon afterSave(), and I bought the Yii Book where afterSave() is mentioned. My problem it that I'm seeing different situations where this is used. I think I'm on the right track, but need the final nail in the coffin regarding this problem. I've tried several variations of the following code, but the following post is the only version not pr
  • Create New...