mediaãã©ã°ã¤ã³å°å ¥(2) 表示
mediaãã©ã°ã¤ã³ã§ãUserã«é¢é£ä»ãã¦attachmentsããã³pp/webroot/media/transfer/img 以ä¸ã«ä¿ç®¡ããç»åã®è¡¨ç¤ºå®è£ ã§ãã
- åè¨äº mediaプラグイン導入(1) 基本的な導入 - 趣味の延長線
追è¨ï¼2/17 0æé
ãfilterã«åºåããã縮å°ç»åã®ä½æã¿ã¤ãã³ã°ã«ãèªèééããããã¾ãããè¨è¼ãä¿®æ£ãã¦èª²é¡ãï¼ã¤è¿½å ãã¾ããã
ã¾ããUserã®æ å ±åå¾ã®éã«ãAtacchmentã®æ å ±ãåæåå¾ã§ããããã«è¨å®ãã¾ãã
/* ã¦ã¼ã¶æ å ±åå¾ */ function getUser($id) { // Media.Attachmentããé¢é£ãã¡ã¤ã«ã®åå¾ +$this->User->hasMany['Attachment']['conditions']['foreign_key'] = $id; + $user = $this->User->find('first', array( 'conditions' => array('User.id' => $id), 'fields' => array( 'User.id', 'User.group_id', 'User.name', 'User.pcmail', 'User.mobile_mail', 'User.modified', ), - 'recursive' => -1, + 'recursive' => 1, + 'contain' => array( + 'Attachment', + ), ));
ããã§Useråå¾åº¦åæã«é¢é£Attachmentã®æ å ±ãå¾ãããããã«ãªãã¾ã*2ã
* User o id 1 (ä¸ç¥ï¼ * Attachment o 0 + dirname transfer/img + basename toomuch.jpg + alternative too (ç¥ï¼
ãããviewã§è¡¨ç¤ºããããã«ãMedia.Mediumãã©ã°ã¤ã³ã追å ãã¾ãã
app_controller.php
--- a/app/controllers/app_controller.php +++ b/app/controllers/app_controller.php @@ -41,6 +41,7 @@ class AppController extends Controller var $helpers = array( 'Html', 'Form', 'Javascript', 'Settings', + 'Media.Medium', 'Token' );
viewã«ã¯ã$medium->embed()ã¡ã½ããã使ç¨ããä¾ãã°ä»¥ä¸ã®ããã«æ¸ãã¾ãã
views/user/index.ctp
+<?php + if (isset($target_user['Attachment'][0])) { + echo $medium->embed($medium->file('filter/s', $target_user['Attachment'][0])); + + } else { + echo " "; + } +?>
ç»åã®èªå縮å°
$medium->fileã®ç¬¬ä¸å¼æ°ã'filter/[ç»åãµã¤ãº]'ã¯å¿
é ã§ãã
ç»åãµã¤ãºã®è¨å®ã«å¿ãã¦ç¸®å°ããç»åããå
ç»åã®ä¿åæã«filter/[ç»åãµã¤ãº]/ã«èªåä½ææ¸ã¿ãªã®ã§ããããimgã¿ã°ã§åºåãã¾ãã
ä¸è¨ã®è¨å®ã§åºåãããimgã¿ã°
<img src="/cake-frame/media/filter/s/transfer/img/toomuch.png" alt="" height="100" width="100">
ç»åã®èªå縮å°è¨å®ã¯ãmediaãã©ã°ã¤ã³ã®core.phpã§è¨å®å¤æ´å¯è½ã§ãã
課é¡
åºæ¬çãªè¡¨ç¤ºã¯ä»¥ä¸ã®éãã§ãããã§ããã°
- altãè¨å®ããã(alternativeã®è¨å®ã§ï¼)
- ãªã³ã¯ä»ãç»åã«ããã
- ç»åãµã¤ãºã¯imgã¿ã°ã®widthã§ã¯ãªãCSSã§èª¿ç¯ããã
- ç»åè¨å®ããªãå ´åãNoimageç»åãåºåããã
- ç»åè¨å®æ¸ã¿ã®å ´åãattachmentsãã«ãã¼ã§è¡¨ç¤ºãããå 容ãç»åå¤æ´ããã¼ãå¤ããã
- png以å¤ã§ãåºåããã(AnimationGIFã¨ãï¼
- ã¢ã¯ã»ã¹ããã¨ãã ãèªå縮å°ç»åãfilterã«åºåããã
- å§ç¸®ï½¥å¤æä¸åãªãã®ãªãªã¸ãã«ç»åã表示ããã
ãªã©ã®å¸æãããã¾ãã
ä¸ï¼ã¤ã¯mediumãã«ãã¼ã ãã§å¯¾å¿ã§ãããã§ããããã以ä¸ã¯æ¡å¼µãã«ãã¼ãªã©ãä½ãå¿ è¦ãããããã§ãã