Jump to content
Larry Ullman's Book Forums

Edward

Members
  • Posts

    1115
  • Joined

  • Last visited

  • Days Won

    27

Everything posted by Edward

  1. I know of some websites using this but it is free depending on how many words you are working on. If you website was low traffic to start off with it would be ideal, google does offer a versatile solution. Apart from the English language what is the other language you wish to support? I'll keep my eye open for you.
  2. This is what i would do if you are going big and you have some dollar https://developers.google.com/translate/v2/pricing
  3. Right i understand what you are saying, i was thinking about it this morning. Another thing you need to look into is the correct data type to use in SQL for saving that duration time. Can you explain to me exactly what units you want the duration time to consist of? May be i can help you with the final solution.
  4. Hmm, there are a several ways of doing this. Actually thinking about this more closely you don't actually need the duration time saved in your database, you could just use the function DateTime code you have used above and calculate the duration time on the fly. Another way would be to only save start time and end time and use the SQL DATEDIFF() to calculate the duration later. This would actually be faster than the DateTime code above, all though the advantage of using the DateTime interval object is that does allow special date formatting. Otherwise you could use one of the following methods in this thread: http://stackoverflow.com/questions/2622774/find-difference-between-two-dates-in-php-or-mysql I would just try keeping things simple for now, when performance becomes more an issue you can go round looking for parts of code to readily fine tune.
  5. I would suggest using the PHP DateTime Class to calculate the difference, http://www.php.net/manual/en/book.datetime.php $d1 = new DateTime($this->registration_date); $d2 = new DateTime(); $dateIntervalObj = $d2->diff($d1);
  6. Okay i am glad that has worked out for you, i like the default method personally in the rules() array. Just looking at that again I think we should be using beforeSave() and not afterSave(), i thought yesterday you misplaced the return parent::afterSave(). Do try before save it must work if its not that it must be something to do with SQL data type used for the duration attribute in the table.
  7. This stuff is definitely covered in Larry's Yii book, you really need to get more into it. I could give some examples but there are so many variations of doing something. I also need to correct some of my own code as later on i found better ways of doing things, Yii takes time and experience to learn, the best way is to get your hands dirty. Don't worry too much about being perfect right now, just have a play around and things will fall in to place. Yeah my best advise for you is to work through the Yii Book, i think the Yii Definitive guide is also good it can make you see things from another angle, which on some occasions can help. If i was to explain stuff to you here it might not make a lot of sense right now until you have a firm grasp of the basics of Yii and its Model View Controller infrastructure.
  8. You need to get your SQL queries into model methods(functions), then call these from the controller then pass the data obtained to your views file from the controller. May be i will have some examples in my project, ill take a look now.
  9. All you need to do is protected function afterSave() { if ($this->isNewRecord) { $this->duration = new CDbExpression('NOW()'); } return parent::afterSave(); } } Or you can add to the rules() array above in your model(), which is actually more tidy, then it could depend on your situation, possibly afterSave is the better way. array('duration', 'default', 'value'=>new CDbExpression('NOW()'), 'on'=>'insert'), If this does not work you need to check your data types you have in your database setting duration to a DATETIME may make a difference that's if its currently a Timestamp. I had the same kind of issue as you, although my code was correct i had to make changes to the database in order to get things running.
  10. I have seen some generated password programs before but usually they display a random password in a HTML division block, then if you wish to select the password you can copy and paste it to somewhere safe followed by clicking on a button to fill in a password input (not a text). But from own experience a feature like this only appeared on the admin side of the website. Nice comment about becoming a painter, you have a sense of humor. Seriously though about my CGridView thread there must be something behind that error if i do figure it out i will update the thread.
  11. Well why don't you view the page source and get the id of the text field you wish to add the value to, id's are usually preset automatically with Yii for forum elements. Or if you wished you could just use html options array and add it to the textfield and add an id in separately. You will need this Id so you can reference the input and add the value in with JQuery, you could use raw javascript if you wished (There are 1000's of scenario's if you search on google for every situation you require). This seems to be fairly simple to me unless there is something i am misunderstanding. I have loads of ajax calls in my scripts in Yii and they all work successfully, sometimes i work the Yii way, sometimes i don't it really depends on the situation.
  12. One thing about gridview also is after you update the whole thing via ajax you loose all your initial js features, so you have to add them to the afterAjaxUpdate function to get them to run again. I used the YiiBooster cgridview extension and i noticed the icon tool tips disappeared, so they needed to be added again manually. Anyway it is all kind of fun, learned such a lot recently.
  13. Strange I tired ending products and re-listing them more than 20 times and today it worked. So computer can behave randomly as shown by the results.
  14. I think you need to email Qiang Xue to ask him why he designed it this way. https://github.com/qiangxue In the CActiveRecord documents they state this: "CActiveRecord is the base class for classes representing relational data. It implements the active record design pattern, a popular Object-Relational Mapping (ORM) technique. Please check the Guide for more details about this class." So maybe you need to look more into the design pattern Object-Relational Mapping ORM to find your answer. The functions also in findByPk also requires some instantated functions in order to work.
  15. You can't do what you are doing above, you do need an instance of the Page model to access that non static method findByPk which is located in CActiveRecord. If you take a look at CActiveRecord which Page Class is an extension of you will find this method * @param string $className active record class name. * @return CActiveRecord active record model instance. */ public static function model($className=__CLASS__) { if(isset(self::$_models[$className])) return self::$_models[$className]; else { $model=self::$_models[$className]=new $className(null); $model->attachBehaviors($model->behaviors()); return $model; } } You can see that the model method is a static method and therefore to use findByPk you must first run this from Page Class to get an instance. Then you can do the following by some extra chaining. $model = Page::model()->findByPk($id); I hope i am making some sense here.
  16. I have built most of the features into a couple of CGridView to finish my scripts. I have a products active Grid and products ended grid. I have added multiple checkboxes in the grids so products can be ended or relisted this works only via ajax call, i have tested this and it works. However if i keep ending and relisting the multiple items many times in a row sometimes the CGridView grid will not remove the product listings even though they have been ended or relisted but counter still updates through ajax to show the correct readings. This to me is a strange error as you can't make it happen by doing the same thing you did last time, it could happen after 5 times or 20 times or could be just 2, i guess it depends how the computer feels, who knows? Does anyone have any insight for this kind of problem? I have a feeling there is something i could have missed here as usually things do work 100% when we have full understanding.
  17. Yes that's cool but my site is not on the server yet, i was looking for something more with javascript features so the image was displayed on the screen once you uploaded it and you can remove it via javascript. The problem with the last script i wrote is that images have to be uploaded to the server and unused images have to be removed later on through a cron job or admin feature. You can't be sure that someone will use that picture that they have uploaded. On my site you can upload 100 pictures or more for an item if you really wanted to, they display on the screen and can be removed via the screen. And the picture's show up again at the point at which you are up to after a php form submission. I spend 6 weeks i think on that uploader part, but like i said the SWFUpload script was built only to handle that page and would take alot of additional coding to handling a single upload so i am looking for something more simple this time. Eh what the heck maybe i will try to make SWFUpload multitask, i guess may be its not that difficult.
  18. Okay ill try to find one that i can use. Doing what you are doing alone is not enough for my situation. Thanks
  19. Jonathon since you are talking about file uploads, can you tell me any Yii extension you would recommend or have had success with for doing this? I used the SWFUpload for loading up multiple pictures but i need to make an upload script for uploading a profile picture and need to use something else, otherwise i will have to try to configure SWFUpload to work for both situations which means doing a lot of extra coding.
  20. Thank you too, Jonathon. I find your posts some of the very most useful of this forum, especially now being more related to Yii. I hope you will hang around on here for a good while.
  21. By the way this method is slightly slower i just tested it against putting the actual ajax request js code within the afterAjaxUpdate. You can test it for yourself and you will notice it updates at the same time without the time lag. I am starting to really love CGridView, it can be a bugger to get to know but somehow it seems to work. I BEG YOUR PARDON Sorry it is the same but for me personally i prefer to add in the js code directly so that its easier to find out quickly what going on with that particular part of cgridview. I do have separate js sheets but on this occasion it isn't really necessary to create more. 'afterAjaxUpdate'=>new CJavaScriptExpression("function(id, data){ $.post( '".Yii::app()->baseUrl."/item/countinventory', function(data){ $('#item-inventory-count').text(data); }, 'html' ); return false; }"),
  22. So it was the afterAjaxUpdate, that was the way i done it, and CJavaScriptExpression is the only way to get the javascript into the widget code. Have you dealt with the session time out problem that CGridView fails to handle where you can override the CWebUser class (That is if you are using session timeouts)? You need to have a bit of patience sometimes to workout some these problems it can take some reading around.
  23. You could authenticate email with your statement if email was passed in place of username $user = User::model()->findByAttributes(array('email'=>$this->username)); That statement seems valid to me. If you wanted to find username you would only then need to do this $username = $user->username; (After you run your above statement) Because you have already received the user record from the email instead. Take into account if you do this you would need to change UserIdentity.php. I would also override the contructor of UserIdentity.php and change to take in parameters $email and $password as apposed to $username and $password.
  24. Do you need help to implement email authentication? Okay i just got a cup of Tea and a lump of chocolate, i am onto it now.
  25. These parts of code can get complicated. Actually you don't need to alter the model because username is already available via $this->username in UserIdentity because $this->_identity=new UserIdentity($this->username,$this->password); as you can see in the above code snipet, the username and password were already passed to the UserIdentity class on its creation in public function login(). class UserIdentity extends CUserIdentity 'This is worth looking at in more detail' Okay now we are in CUserIdentity below you can see the public $username and $password class CUserIdentity extends CBaseUserIdentity { /** * @var string username */ public $username; /** * @var string password */ public $password; /** * Constructor. * @param string $username username * @param string $password password */ public function __construct($username,$password) { $this->username=$username; $this->password=$password; } So in your userIdentity class something basic like this will do the trick class UserIdentity extends CUserIdentity { private $_id; public function authenticate() { // Load model for username and email by active record $user = User::model()->findByAttributes(array('username'=>$this->username)); if($user === null) $this->errorCode=self::ERROR_USERNAME_INVALID; else if($user->password !== hash_hmac('sha256', $this->password, Yii::app()->params['encryptionKey'])) $this->errorCode=self::ERROR_PASSWORD_INVALID; else { $this->errorCode = self::ERROR_NONE; $this->_id = $user->id; } return !$this->errorCode; } public function getId() { return $this->_id; } } I hope this helps you get the picture, it took me a while to work that part out myself.
×
×
  • Create New...