Yii framework_エンジニア勉強会20140226
Upcoming SlideShare
Loading in...5
×
 

Yii framework_エンジニア勉強会20140226

on

  • 398 views

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

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

Statistics

Views

Total Views
398
Views on SlideShare
398
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Yii framework_エンジニア勉強会20140226 Yii framework_エンジニア勉強会20140226 Presentation Transcript

  • Yii Framework Best Practices & Hints
  • 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);
  • 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);
  • 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();
  • 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), ); }
  • 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'); ?>
  • 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
  • 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後払いモジュール';