Sunday, June 30, 2013

Yii Active Records

Yii Active Record

PostController.php

//Assuming we have a database table with ID, title, content, category_id and user_id as a field

public function actionActiveRecord()
{
  //example of what Yii Active record can return
  $model = Post::model()->find('id = 1');
  echo $model->title;
  $model = Post::model()->find('category_id = 2 AND user_id = 1');
  echo $model->title;

  //alternatively you can use Yii Active record find by attributes
  $model = Post::model()->findByAttributes(array(
      'category_id' => 2,
      'user_id'     => 1,
  ));
 
  echo $model->title;

  //or you can use findByPk
  $model = Post::model()->findByPk(1)

  //if you need to display more than 1 data findAll
  $model = Post::model()->findAll('category_id = 2');
  foreach($model as $m){
    echo $m->title."<br/>";
    echo $m->content."<br/>";
  }
}

How to enable Gii Tools In YII

Setting GII Tools in YII

1. Open your_app/protected/config/main.php
2. uncomment the following th enable the Gii tool
/*
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'Enter Your Password Here',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
*/

3. The UrlManager code needs to be uncommented as well
/*
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),*/
4. Change the Gii password
5. Go to your localhost/your_app/gii

Saturday, June 29, 2013

How To Install YII Framework on Windows

Step By Step Guide to Install YII Framework on Windows

Installing YII Framework on Windows

1. Download YII framework on www.yiiframework.com
2. Install XAMPP
3. Put YII framework (rename to YII) on the XAMPP folder. e.g c:/xampp/yii
4. Open System Properties -> Advanced -> Environment Variables -> Edit System Variables (PATH) -> Put YII path into the
system variables. e.g c:/xampp/YII;c:/xampp/php
5. Open CMD
6. Go to c:/xampp/htdocs/
7. Execute "yiic webapp your_app"
8. Automatically your_app will be generated
9. Open localhost/your_app

Yiic will automatically generate your web application.

PS C:\xampp\htdocs> yiic webapp your_app
Create a Web application under 'C:\xampp\htdocs\your_app'? (yes|no) [no]:yes
      mkdir C:/xampp/htdocs/your_app
      mkdir C:/xampp/htdocs/your_app/assets
      mkdir C:/xampp/htdocs/your_app/css
   generate css/bg.gif
   generate css/form.css
   generate css/ie.css
   generate css/main.css
   generate css/print.css
   generate css/screen.css
      mkdir C:/xampp/htdocs/your_app/images
   generate index-test.php
   generate index.php
      mkdir C:/xampp/htdocs/your_app/protected
   generate protected/.htaccess
      mkdir C:/xampp/htdocs/your_app/protected/commands
      mkdir C:/xampp/htdocs/your_app/protected/commands/shell
      mkdir C:/xampp/htdocs/your_app/protected/components
   generate protected/components/Controller.php
   generate protected/components/UserIdentity.php
      mkdir C:/xampp/htdocs/your_app/protected/config
   generate protected/config/console.php
   generate protected/config/main.php
   generate protected/config/test.php
      mkdir C:/xampp/htdocs/your_app/protected/controllers
   generate protected/controllers/SiteController.php
      mkdir C:/xampp/htdocs/your_app/protected/data
   generate protected/data/schema.mysql.sql
   generate protected/data/schema.sqlite.sql
   generate protected/data/testdrive.db
      mkdir C:/xampp/htdocs/your_app/protected/extensions
      mkdir C:/xampp/htdocs/your_app/protected/messages
      mkdir C:/xampp/htdocs/your_app/protected/migrations
      mkdir C:/xampp/htdocs/your_app/protected/models
   generate protected/models/ContactForm.php
   generate protected/models/LoginForm.php
      mkdir C:/xampp/htdocs/your_app/protected/runtime
      mkdir C:/xampp/htdocs/your_app/protected/tests
   generate protected/tests/bootstrap.php
      mkdir C:/xampp/htdocs/your_app/protected/tests/fixtures
      mkdir C:/xampp/htdocs/your_app/protected/tests/functional
   generate protected/tests/functional/SiteTest.php
   generate protected/tests/phpunit.xml
      mkdir C:/xampp/htdocs/your_app/protected/tests/report
      mkdir C:/xampp/htdocs/your_app/protected/tests/unit
   generate protected/tests/WebTestCase.php
      mkdir C:/xampp/htdocs/your_app/protected/views
      mkdir C:/xampp/htdocs/your_app/protected/views/layouts
   generate protected/views/layouts/column1.php
   generate protected/views/layouts/column2.php
   generate protected/views/layouts/main.php
      mkdir C:/xampp/htdocs/your_app/protected/views/site
   generate protected/views/site/contact.php
   generate protected/views/site/error.php
   generate protected/views/site/index.php
   generate protected/views/site/login.php
      mkdir C:/xampp/htdocs/your_app/protected/views/site/pages
   generate protected/views/site/pages/about.php
   generate protected/yiic
   generate protected/yiic.bat
   generate protected/yiic.php
      mkdir C:/xampp/htdocs/your_app/themes
      mkdir C:/xampp/htdocs/your_app/themes/classic
      mkdir C:/xampp/htdocs/your_app/themes/classic/views
   generate themes/classic/views/.htaccess
      mkdir C:/xampp/htdocs/your_app/themes/classic/views/layouts
      mkdir C:/xampp/htdocs/your_app/themes/classic/views/site
      mkdir C:/xampp/htdocs/your_app/themes/classic/views/system

Your application has been created successfully under C:\xampp\htdocs\your_app.

Wednesday, June 26, 2013

How to Startup Tomcat server in MAC

How to Startup/Shutdown Tomcat server in MAC

/Library/tomcat/bin/startup.sh
/Library/tomcat/bin/shutdown.sh

Saturday, June 22, 2013

How to display .gitignore file in netbeans

To display .gitignore file in netbeans simply modify the miscellaneous options in:

Tools->Options->miscellaneous ->Files

And change the Files ignore by the IDE:
From:
^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn)$|~$|^\.(?!(htaccess)$).*$

To:
^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn)$|~$|^\.(?!(htaccess|gitignore)$).*$

Friday, June 21, 2013

CSS style submit button height

To adjust the text on the submit input button use the following CSS style:

line-height: 2;

Monday, June 3, 2013

Unable to create Git index.lock File Exists

fatal: Unable to create '/Users/username/Sites/testsite/.git/index.lock': File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

Just delete the index.lock file

rm /Users/username/Sites/testsite/.git/index.lock
git pull

Sunday, June 2, 2013

Apache Access Log, Error Log in Mac

is located in

tail - f /var/log/apache2/access_log
tail - f /var/log/apache2/error_log