- open cmd (as an admin)
- type:
mklink /d linkpath targetpath
example:
mklink /d c:\easytoremember c:\users\neil\local\applicationdata\temp\hardtoremember
Quick snippets to get you up to speed with the Yii PHP framework. By Neil McGuigan.
mklink /d linkpath targetpath
mklink /d c:\easytoremember c:\users\neil\local\applicationdata\temp\hardtoremember
class OCCActiveRecord extends CActiveRecord{ public $checksum = null; public function afterFind(){ /* get a checksum of all the attribute values after reading a record from db */ $this->checksum = md5(implode('', $this->getAttributes(false))); parent::afterFind(); } public function rules(){ /* use an exist validator to make sure that a record with the same checksum is still in db. if it's been modified, then checksums will be different */ return array( array('id', 'exist', 'message'=>'This record was modified after you read it', 'on'=>'update', 'criteria'=>array('condition'=>'md5(concat('.implode(',',$this->attributeNames()).'))=:checksum', 'params'=>array('checksum'=>$this->checksum))) ); } }Just a rough sketch, but you get the idea.
CREATE TABLE `tbl_party` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type` char(1) NOT NULL comment 'p=person,o=organization', `name` varchar(255) NOT NULL comment 'surname if a person', `given_name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ;
class Party extends CActiveRecord { public static function model($className=__CLASS__){ return parent::model($className); } public function tableName(){ return 'tbl_party'; } public function relations(){ return array( ); } public function rules(){ return array( array('name,type','required'), array('type','in', 'range'=>array('o','p')) ); } } class Person extends Party { /* this is required for subtypes */ public static function model($className=__CLASS__){ return parent::model($className); } public function defaultScope(){ /* only read Parties that are People */ return array( 'condition'=>"type='p'" ); } public function relations(){ /* combine parent and own relations. can have 'People' only relations */ $parentRelations = parent::relations(); $myRelations = array( ); return array_merge($myRelations, $parentRelations); } public function rules(){ /* combine parent and own rules */ $parentRules = parent::rules(); $myRules = array( array('type', 'default', 'value'=>'p'), /* set type to Person */ array('type', 'in', 'range'=>array('p')), /* allow only Person type */ array('given_name', 'required') /* new rule for this subtype only */ ); /* you want to apply parent rules last, delete them here if necessary */ return array_merge($myRules, $parentRules); } } class Organization extends Party { public static function model($className=__CLASS__){ return parent::model($className); } public function defaultScope(){ return array( 'condition'=>"type='o'" ); } public function relations(){ $parentRelations = parent::relations(); $myRelations = array( ); return array_merge($myRelations, $parentRelations); } public function rules(){ $parentRules = parent::rules(); $myRules = array( array('type', 'default', 'value'=>'o'), array('type', 'in', 'range'=>array('o')) ); /* you want to apply parent rules last. delete them if necessary */ return array_merge($myRules, $parentRules); } }
public function actionCreate() {
//read the post input (use this technique if you have no post variable name): $post = file_get_contents("php://input"); //decode json post input as php array: $data = CJSON::decode($post, true); //contact is a Yii model: $contact = new Contact(); //load json data into model: $contact->attributes = $data;
//this is for responding to the client: $response = array(); //save model, if that fails, get its validation errors: if ($contact->save() === false) { $response['success'] = false; $response['errors'] = $contact->errors; } else { $response['success'] = true; //respond with the saved contact in case the model/db changed any values $response['contacts'] = $contact; } //respond with json content type: header('Content-type:application/json');
//encode the response as json: echo CJSON::encode($response); //use exit() if in debug mode and don't want to return debug output exit(); }