Yii framework_エンジニア勉強会20140226

1,245 views

Published on

2月26日に開催されたエスキュービズムエンジニア勉強会での資料になります。

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,245
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Yii framework_エンジニア勉強会20140226

  1. 1. Yii Framework Best Practices & Hints
  2. 2. CActiveRecord & CDbCriteria Simple Search: $model = new User(); $model->getDbCriteria()->compare('id', $user_id); $model->getDbCriteria()->compare('name', $user_name); $models = $model->findAll(); $model = new User(); $criteria=new CDbCriteria; $criteria->compare('id', $user_id); $criteria->compare('name', $user_name); $models = $model->findAll($criteria);
  3. 3. CActiveRecord & CDbCriteria Operator Search: $model = new User(); $model ->getDbCriteria()->addCondition("birthDate <= :eighteenPlus"); $model ->getDbCriteria()->params[':eighteenPlus]=$eighteenPlus; $model ->getDbCriteria()->compare("birthDate",$eighteenPlus,false,"<="); Possible Operators: <> <= >= < > = Like Search: $model = new User(); $model ->getDbCriteria()->compare("name", $initials, true);
  4. 4. CActiveRecord & CDbCriteria Nested Conditions Search: $model = new User(); $model->getDbCriteria()->compare('id', $user_id); $model->getDbCriteria()->compare('name', $user_name); $criteria = new CDbCriteria(); $criteria->compare('del_flag', false, false, 'OR'); $criteria->compare('del_flag', null, false, 'OR'); $model->getDbCriteria()->mergeWith($criteria); $models = $model->findAll();
  5. 5. CActiveRecord & CDbCriteria Relational Search: $model = new User(); $model ->with('UserAddress'); $model ->with('UserContact'); $model ->getDbCriteria()->together = false; $model->getDbCriteria()->compare('id', $userId); $model->getDbCriteria()->compare('name', $userName); $model->getDbCriteria()->compare('UserContact.phoneNumber', $phoneNumber); /protected/models/User.php public function relations() { return array( 'productsClass' => array(self::HAS_MANY, 'UserAddress', 'user_id'), 'productCategory' => array(self::HAS_MANY, 'phoneNumber', 'user_id), ); }
  6. 6. CActiveRecord & CDbCriteria Populate: $model->attributes = $_POST['NpSettingsForm']; <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'npPostPaySettings', 'htmlOptions'=>array( 'class'=>'form-horizontal text-right', ), 'enableAjaxValidation'=>false, 'enableClientValidation' => true, )); ?> <?php echo $form->labelEx($model,'spCode'); ?> <?php echo $form->TextField($model,'spCode'); ?> <?php echo $form->labelEx($model,'terminalId); ?> <?php echo $form->TextField($model,'terminalId'); ?>
  7. 7. Modules Folder Structure: forum/ ForumModule.php components/ views/ controllers/ DefaultController.php extensions/ models/ views/ layouts/ default/ index.php the module class file containing reusable user components containing view files for widgets containing controller class files the default controller class file containing third-party extensions containing model class files containing controller view and layout files containing layout view files containing view files for DefaultController the index view file
  8. 8. Modules Initial Settings: /protected/config/main.php $modules = array( 'forum', ); Module Class: /protected/modules/forum/ForumModule.php class NpPostPayModule extends CWebModule { const MODULE_ID = 401; const MODULE_CODE = 'mdl_np'; const MODULE_NAME = 'NP後払いモジュール';

×