Actions

Contractor Financials Development

From zen2

Revision as of 08:08, 25 July 2013 by Chris (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Preliminaries

Apache must have rewrite enabled to allow for tidy URLs: Enable_Apache_Rewrite_via_htaccess#2nd_Method

Install Yii

Now we can get the latest version of the Yii Framework. For development I'm installing it to ~/Network/Apps/WebDev Next what we will do is create a soft link called "current" to that release folder that way if we change the Yii Framework version, we can do so just updating the sym link

sudo ln -s /home/nitrous/orac/software/WebDev/yii-1.x.xxxx yii

Yii Skeleton

mkdir /var/www/cf
cd /var/www/cf
../yii/framework/yiic webapp /var/www/cf 
  • Edit /var/www/cf/protected/config/main.php where it says // uncomment the following to use a MySQL database
''db'=>array(
			'connectionString' => 'mysql:host=localhost;dbname=cf',
			'emulatePrepare' => true,
			'username' => 'root',
			'password' => '********',
			'charset' => 'utf8',
		),
  • Add User Management Module
cd protected
mkdir modules
cd modules
wget http://www.yiiframework.com/extension/yii-user-management/files/User_Management_Module_0.5.tar.bz2
tar xvf User_Management_Module_0.5.tar.bz2

Follow instructions in protected/modules/user/docs/InstallTutorial.txt

  • Enable tidy URLSs: edit /protected/config.main.php and look for "// uncomment the following to enable URLs in path-format" and uncomment it.
  • To enable Gii add the following to protected/config/main.php
'modules' => array(
...
                               'gii'=>array(
					'class'=>'system.gii.GiiModule',
					'password'=>'pick up a password here',
				)

Database

  • Create cf database
    • address
    • business
    • cashbook
    • sales_tax_rate
    • sales_tax_type
    • to_from
    • transaction_category
    • transaction_reference

Points to Note

  1. Yii is case sensitive, so start tables with lower-case and create model in Yii with a lowercase too (from skelton returning lowercase table names)


Create Modules

  • http://localhost/cf/index.php/gii
  • Create module eg business
  • Create model for module eg:
    • table name: business
    • model class: Business
    • model path: business.models
  • Create CRUD for module eg:
    • Model class: business.models.Business
    • Controller ID: business/Business
  • Add business module, edit /protected/config/main.php and add business under modules

Edit Models

public function relations()

public function relations()
	{
		return array(
				'created_by'=>array(self::BELONGS_TO, 'User', 'created_by_ID'),
        		'modified_by'=>array(self::BELONGS_TO, 'User', 'modified_by_ID'),
        		'sales_tax_type'=>array(self::BELONGS_TO, 'Sales_tax_types', 'sales_tax_type_ID'),
            	
		);
	}

public function rules()

public function rules()
	{
		return array(
        array('tax_code', 'required'),
        array('tax_code', 'length', 'max'=>64),
        array('tax_description', 'required'),
        array('tax_description', 'length', 'max'=>256),
        );
       
    }

public function safeAttributes()

public function safeAttributes()
{
    return array('title', 'content', 'status', 'tags');
}

RBAC Authorization

RBAC table scheme it can be found at /framework/web/auth/schema.sql

Add this to config/main.php

'authManager'=>array(
            'class'=>'CDbAuthManager',
            'connectionID'=>'db',
        ),