To automate whodidit and timestamps in yii activerecord model using beforesave() method. If the rule validation got success then only the beforesave() method will invoke. Without satisifying rule() in activerecord model, this method will not work. [php] protected function beforeSave() { if(parent::beforeSave()) { if($this->isNewRecord) { $this->created_on = time(); $this->created_by = (int)Yii::app()->user->id; } $this->updated_on = time(); …
Category: Ubuntu
Permanent link to this article: https://blog.openshell.in/2013/03/how-to-automate-whodidit-behaviour-and-timestamps-in-yii-activerecord-model/
Mar 17
How to automate timestamps in activerecord using yii
There are many ways to automate the setting of timestamps in yii ActiveRecord models. In this we are representing three ways here. 1) Update via model’s rules: [php] /** * @return array validation rules for model attributes. */ public function rules() { return array( array(‘title’,’length’,’max’=>255), array(‘title, created_at, updated_at’, ‘required’), array(‘updated_at’,’default’, ‘value’=>new CDbExpression(‘NOW()’), ‘setOnEmpty’=>false,’on’=>’update’), array(‘created_at,updated_at’,’default’, ‘value’=>new …
Permanent link to this article: https://blog.openshell.in/2013/03/how-to-automate-timestamps-in-activerecord-using-yii/
Permanent link to this article: https://blog.openshell.in/2013/03/whats-the-difference-between-list-tuples-and-dictionaries-in-python/
Mar 15
Execute Shell file in linux server
chmod Command: Run Shell Script In Linux Set an executable permission using the chmod command as follows: [code]chmod +x file.sh[/code] Now your can run your .sh file as follows: Execute Shell Script Using . ./ (dot space dot slash) [code]./file.sh[/code] You can also execute a unix shell script by specifying the interpreter in the command …
Permanent link to this article: https://blog.openshell.in/2013/03/execute-shell-file-in-linux-server/
Mar 15
How to configure python with apache in ubuntu?
Common Gateway Interface(CGI) helps you run python application in apache webserver in ubuntu. Follow the steps which help you to configure python with apache webserver. Step 1: [code] sudo mkdir /var/www/python [/code] Step 2: [code] sudo vim /etc/apache2/sites-available/default [/code] Step 3: Add the following lines in “default” file and save the file. [code] ScriptAlias /python/ /var/www/python/ …
Permanent link to this article: https://blog.openshell.in/2013/03/how-to-configure-python-with-apache-in-ubuntu/
Mar 15
how to install easy_install in ubuntu?
To installing easy_install in ubuntu is very easy, just follow the instructions below. [code] $ sudo apt-get install python-setuptools [/code] And that’s it! Yes, that’s all you need to do and you will have easy_install available at the command prompt. In case you are wondering, easy_install is a Python module which comes as a part …
Permanent link to this article: https://blog.openshell.in/2013/03/how-to-install-easy_install-in-ubuntu/
Permanent link to this article: https://blog.openshell.in/2013/03/how-to-use-multi-line-comment-in-python/
Mar 15
How to install MySQLdb module in python
To install MySQLdb module in python, download it from MySQLdb Download page Finally, execute the following command to configure mysqldb with python: [code] $ tar xfz MySQL-python-1.2.4b4.tar.gz $ cd MySQL-python-1.2.4b4 $ # edit site.cfg if necessary $ python setup.py build $ sudo python setup.py install # or su first [/code]
Permanent link to this article: https://blog.openshell.in/2013/03/how-to-install-mysqldb-module-in-python/
Mar 14
Fatal error: Python.h: No such file or Directory
When i tried to build mysql connector for python got the below error: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,’beta’,4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g _mysql.c:29:20: fatal error: Python.h: No such file or directory compilation terminated. error: command ‘gcc’ failed with exit status 1 Where can …
Permanent link to this article: https://blog.openshell.in/2013/03/fatal-error-python-h-no-such-file-or-directory/
Mar 14
How to install python in ubuntu
Install python in ubuntu machine by follow the below steps, Which helps to install all necessary packages needed. 1) To be able to compile Python Source, you will need few packages. Open terminal and execute this command [code]sudo apt-get install build-essential gcc libncursesw5-dev libreadline-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev[/code] 2) Then execute this command …
Permanent link to this article: https://blog.openshell.in/2013/03/how-to-install-python-in-ubuntu/
Mar 15
How to use multi-line comment in python?
March 15, 2013
Python doesn’t have a multi-line comment. Most people who want to do a multi-line comment just use triple quoted strings. [code] ”’ for example you could do something like this as a multi-line comment ”’ [/code] But personally, I will do it like this: [code] # This # is # a # multi-line # comment …
Continue reading