Jump to content
Larry Ullman's Book Forums

Edward

Members
  • Posts

    1115
  • Joined

  • Last visited

  • Days Won

    27

Everything posted by Edward

  1. Jonathon, i have a question. Does your website handle multiple shopping carts for one active user?
  2. Its good we finally managed to work it out together with this code i knew it was nothing that we couldn't handle. If you have any other issues in the future i would be happy to help of course them being Yii related questions.
  3. The checkAccess() method performs an access check for the user we both should be using either Yii::app()->user->Name or Yii::app()->user->Id to find the actual username of the logged in user for static authentication values which you have. I hope for both of our sakes we have the correct answer this time. 'visible'=>"(Yii::app()->user->Name==='admin') ? true : false;", This was actually the first time i had to go into investigate CWebUser a little more, i didn't understand my self why static actually work but now i do. I am using database authentication with my website but i truly understand why you are using static values, if i were in your situation i would do the same.
  4. You can fix that problem in CGridView by adding in this to the visible array key 'visible'=>"(Yii::app()->user->checkAccess('admin')) ? true : false;", I would code the expression without the ! NOT and use the tenary operator, so if this is admin then visibility is true otherwise it will result in false.
  5. Is it possible you can add into a post your full code for CGridView, then i can test it on my computer for errors. I did use the YiiBooster CGridView extension for that widget but regardless of that the coding should be similar.
  6. @Ron Which part of the code is throwing the array. Just checking you did add that code in your CGridView widget code right? @Larry Yeah i know what you mean, i kind of know i can do it but sometimes it doesn't always happen every time you are at the computer, i worked about 5 hours before trying to give that a bash brain was fried. I hope when my brain is fresh i can get it worked out, hahaha. I'll see what i come up with first and if i can't get it ill post up what i have so far and then you can hopefully help me find a final solution. Thanks
  7. No problem but sometimes i wonder if someone could help me also or have a Yii solutions. By the way i know what you mean about Yii and coding your website for the first time, Ive had to go back and recode a lot of stuff. I couldn't really see what was the best way of doing things until later down the line but anyway it seems like Ive taken a massive jump this year regardless of that.
  8. Edward

    Prg

    I have been working on other stuff and have to come back to this but as far as i know the Session tokens don't work with refreshing or clicking browser back button so you need to use POST/REDIRECT/GET design pattern. I will test both and let you know what i come up, all the online help is very iffy.
  9. Actually this should work fine as you have it, works for me 'visible'=>!Yii::app()->user->isGuest, or 'visible'=> (Yii::app()->user->isGuest) ? false : true,
  10. The edit for CGridView would be made in the view .php file, so what ever the name of your view would be.
  11. I will help you with customizations CGridView as i believe one coded correctly is better than having two. You know what i mean repeated code is something we should all be avoiding. I did mention something about this already in post #6 which i made, i also found this post http://stackoverflow.com/questions/9429987/cgridview-conditional-delete-button I have provided part of my code below and also delete parts out so not all there but that was how i customized in my CGridView. I have actually come across two things in CGridView that do not work at all but all the below works well, don't forget your CHtml::Encode i left mine out till later. You will need to identify whether the user is an admin or user then make a php expression for this in the visible array key value then the job will be done. 'columns'=>array( array ( 'name'=>'Payment Address', 'header'=>'Payment Address', 'value'=>function($data){ $checked = false; if($data->payment_address === 'yes') $checked = true; return CHtml::radioButton('paymentAddress',$checked,array('id'=>$data->id,'value'=>$data->id)); }, 'type'=>'raw', ), array( 'class'=>'bootstrap.widgets.TbButtonColumn', 'template'=>'{addressUpdate}{addressDelete}', 'buttons'=>array( 'addressUpdate'=>array( 'label'=>'Update Address', 'icon'=>'icon-pencil', 'imageUrl'=>false, 'url'=>'Yii::app()->createUrl("address/update", array("id"=>$data->id))', 'options'=>array('class'=>'addressUpdate'), ), 'addressDelete'=>array( 'label'=>'Delete Address', 'icon'=>'icon-remove', 'imageUrl'=>false, 'click' => new CJavaScriptExpression(""), 'url'=>'Yii::app()->createUrl("address/delete", array("id"=>$data->id))', 'options'=>array('class'=>'addressEnd'), 'visible'=>'($data->registration_address === "yes") ? false : true;', ), ), ),
  12. Edward

    Prg

    Just an update i did get some positive from this but if you redirect the browser back it still does duplicate submissions. By the way i am well aware how to stop this with Javascript, what i am looking for is a bullet proof php solution. Use PHP sessions to set a session variable (for example $_SESSION['posttimer']) to the current timestamp on post. Before actually processing the form in PHP, check if the $_SESSION['posttimer'] variable exists and check for a certain timestamp difference (IE: 2 seconds). This way, you can easily filter out double submits. Example: // form.html <form action="foo.php" method="post"> <input type="text" name="bar" /> <input type="submit" value="Save"> </form> // foo.php if (isset($_POST) && !empty($_POST)) { if (isset($_SESSION['posttimer'])) { if ( (time() - $_SESSION['posttimer']) <= 2) { // less then 2 seconds since last post } else { // more than 2 seconds since last post } } $_SESSION['posttimer'] = time(); } Update what i could do is create another controller action user/createsuccess for example redirect to this after user/create, then if the user tried to click back they will be at user/createsuccess where you could then redirect them back to the page after.
  13. Edward

    Prg

    Hi Larry i know you are a busy man but i would like to see how you would implement this successfully in Yii, i need this all over my website and i haven't found any method that successfully works yet. http://en.wikipedia.org/wiki/Post/Redirect/Get If anyone has any methods that work for duplicate submission please let me know below, i tried a few and they failed to work. http://stackoverflow.com/questions/2133964/how-to-prevent-multiple-inserts-when-submitting-a-form-in-php Even this forum cannot protect against it when JS is disabled, so what is the solution?
  14. This looks good but why didn't you just direct admin or the user to the same CGridView or which ever presentation grid you were using to present your data and then just disable its attributes depending on the user. I think that way you can save all the cloning. Gii can generate new crud functionality but it would be the same as you already have. You could just make a new controller name and generate some new crud then copy and paste over the templates deleting these files when you are finished. Personally i don't see the point in this, it would be far quicker just to make a new view.php file and just copy and paste code over and tweaking it a bit but still its not better than the above i suggested. The widgets are easily customizable its far easier to just tweak them a bit.
  15. Try this instead: 'visible'=> (Yii::app()->user->isGuest) ? false : true,
  16. If you go into CWebUser you can find the following, it surprises me why that worked at first but it can be explained. public $loginUrl=array('/site/login'); /** * Returns the URL that the user should be redirected to after successful login. * This property is usually used by the login action. If the login is successful, * the action should read this property and use it to redirect the user browser. * @param string $defaultUrl the default return URL in case it was not set previously. If this is null, * the application entry URL will be considered as the default return URL. * @return string the URL that the user should be redirected to after login. * @see loginRequired */ public function getReturnUrl($defaultUrl=null) { if($defaultUrl===null) { $defaultReturnUrl=Yii::app()->getUrlManager()->showScriptName ? Yii::app()->getRequest()->getScriptUrl() : Yii::app()->getRequest()->getBaseUrl().'/'; } else { $defaultReturnUrl=CHtml::normalizeUrl($defaultUrl); } return $this->getState('__returnUrl',$defaultReturnUrl); } /** * @param string $value the URL that the user should be redirected to after login. */ public function setReturnUrl($value) { $this->setState('__returnUrl',$value); }
  17. Yes i also agree that would be a perfect method i have also done something similar you can use the 'visible' CButtonColumn feature and fill it in with php expression to disable it in a certain situation. I disabled users from being able to remove their registration address while other addresses like their shipping and payment addresses could be deleted. I think i am still learning things about CGridView but i really love it a lot now, we are truly blessed to have such great widgets. I used this php expression in my code, however you will have to tweak it to your situation with the users 'visible'=>'($data->registration_address === "yes") ? false : true;',
  18. If you are using static values for logging in users you can do it the way you are doing it and just use the standard rules like you are using array('allow', // allow admin user to perform 'admin' and 'delete' actions 'actions'=>array('admin','delete'), 'users'=>array('admin'), The way i suggested it was having users logged in the database but you are definitely right if its just a small site that would be ideal the way you have it.
  19. If i was you i would just create another controller action and render the view according to whether a user was an admin or user viewing the page. Here is a sample for the view action in the controller. You will also require two view files in your views folder under the controller name you wish to execute these actions admin_view.php and user_view.php. public function actionView($id) { if(Yii::app()->user->type === 'admin') { $this->render('admin_view',array( 'model'=>$this->loadModel($id), )); } else { $this->render('user_view',array( 'model'=>$this->loadModel($id), )); } } You will also be required to set the type of user in components/userindentity.php $this->setState('type',$user->type); This value can be given from loading up the users records from the database through active record. In your accessRules() in your controller you will also need to setup a little better authentication if you are using the setState and saving user type for example array('allow', // allow admin only for these actions 'actions'=>array('admin','index'), 'users'=>array('@'), 'expression'=>"isset(Yii::app()->user->type) && (Yii::app()->user->type === 'admin')", Hope this helps out.
  20. Glad you got it worked out, thanks for sharing your solution with us.
  21. I assume your HAS_MANY relationship is correct in your Users model. I could try to make a guess as to what your $query variable holds but i would most definitely be wrong, i would take a closer look at that and the following thread. Just to brush up on working with Related models in this situation. http://www.yiiframework.com/forum/index.php/topic/20442-model-search-criteria-on-related-record/page__view__findpost__p__100148
  22. Glad you managed to get that worked out thanks for sharing the solution.
  23. Good going Jonathon. I hope you will show us the site when you get it completed. Best of luck on the remaining 20%.
  24. I found a good currency api if you are interested its free if you update a couple of times a day. But you have to pay if you want updates every second. I will let you know if i find anything. What kind of percentage is your website complete now? You are actually a motivator for me to get mine done i think im about 20%.
  25. I am not clear of what you are doing here, are you creating your own widget? What is a Site model? What is the function of your forum with two text inputs? What are the vales supposed to be, why and what are you populating the remaining text input with? (Regarding this post 'I love the Yii widgets, it was all my fault things went wrong before, i love the them almost as much as my love for Larry himself'. Sorry for my negative attitude regarding widgets before, its all positive now. If you have any questions on how to do things with the CGridView, CDetailView etc Edward is the person to ask. If you have any questions bring them on, i would love to express my love from them in helping you.
×
×
  • Create New...