現在『 booked 』 という予約管理システムのオープンソースを改修しています。
booked は 画面表示に tplファイルを使うらしく、
試しに画面に1項目増やしてみているのですが、値が表示されません。
以下該当コードとなります。
データ格納部分
PHP
1<?php 2 3require_once(ROOT_DIR . 'Pages/Reservation/ReservationPage.php'); 4 5interface IExistingReservationPage extends IReservationPage 6{ 7 8// 省略 9 10 /** 11 * @param $test string 12 */ 13 // 追加部分 14 function SetTest($test); 15} 16 17class ExistingReservationPage extends ReservationPage implements IExistingReservationPage 18{ 19 protected $IsEditable = false; 20 protected $IsApprovable = false; 21 22 public function __construct() 23 { 24 parent::__construct(); 25 } 26 27 public function PageLoad() 28 { 29 parent::PageLoad(); 30 } 31 32 protected function GetPresenter() 33 { 34 $preconditionService = new EditReservationPreconditionService(); 35 $reservationViewRepository = new ReservationViewRepository(); 36 37 return new EditReservationPresenter($this, 38 $this->LoadInitializerFactory(), 39 $preconditionService, 40 $reservationViewRepository); 41 } 42 43 protected function GetTemplateName() 44 { 45 $readOnly = $this->GetQuerystring(QueryStringKeys::READ_ONLY) == 1; 46 47 if (!$readOnly && $this->IsApprovable && !$this->UpdatingBeforeApproving()) 48 { 49 return 'Reservation/approve.tpl'; 50 } 51 if (!$readOnly && $this->IsEditable) 52 { 53 return 'Reservation/edit.tpl'; 54 } 55 return 'Reservation/view.tpl'; 56 } 57 58 protected function GetReservationAction() 59 { 60 return ReservationAction::Update; 61 } 62 63 public function SetAdditionalResources($additionalResourceIds) 64 { 65 $this->Set('AdditionalResourceIds', $additionalResourceIds); 66 } 67 68 // 試しに追加してみたところ 69 public function SetTest($test) 70 { 71 $this->Set('Testtest', "Testtest"); 72 } 73} 74 75class DuplicateReservationPage extends ExistingReservationPage 76{ 77 public function __construct() 78 { 79 parent::__construct(); 80 $this->Set('Title', Resources::GetInstance()->GetString('DuplicateReservation')); 81 } 82 83 protected function GetTemplateName() 84 { 85 return 'Reservation/create.tpl'; 86 } 87 88 public function PageLoad() 89 { 90 parent::PageLoad(); 91 92 $this->Set('ReturnUrl', urldecode($this->GetQuerystring('return'))); 93 } 94 95 protected function GetReservationAction() 96 { 97 return ReservationAction::Create; 98 } 99 100 protected function GetReturnUrl() 101 { 102 return urldecode($this->GetQuerystring(QueryStringKeys::REDIRECT)); 103 } 104 105 public function SetTermsAccepted($accepted) 106 { 107 $this->Set('TermsAccepted', false); 108 } 109}
継承元ファイル(特に変更なし)
PHP
1<?php 2 3require_once(ROOT_DIR . 'Pages/SecurePage.php'); 4require_once(ROOT_DIR . 'Presenters/Reservation/ReservationPresenter.php'); 5 6interface IReservationPage extends IPage 7{ 8 /** 9 * @param $startPeriods array|SchedulePeriod[] 10 * @param $endPeriods array|SchedulePeriod[] 11 * @parma $lockDates bool 12 */ 13 public function BindPeriods($startPeriods, $endPeriods, $lockPeriods); 14 15 /** 16 * @param $resources array|ResourceDto[] 17 */ 18 public function BindAvailableResources($resources); 19 20 /** 21 * @param $accessories Accessory[] 22 */ 23 public function BindAvailableAccessories($accessories); 24 25 /** 26 * @param IResource $resource 27 */ 28 public function SetReservationResource($resource); 29 30 /** 31 * @param ReservationUserView[] $participants 32 */ 33 public function SetParticipants($participants); 34 35 /** 36 * @param ReservationUserView[] $invitees 37 */ 38 public function SetInvitees($invitees); 39 40 /** 41 * @param $accessories ReservationAccessory[]|array 42 */ 43 public function SetAccessories($accessories); 44 45 /** 46 * @param $attachments ReservationAttachmentView[]|array 47 */ 48 public function SetAttachments($attachments); 49 50 /** 51 * @param bool $canShowAdditionalResources 52 */ 53 public function ShowAdditionalResources($canShowAdditionalResources); 54 55 /** 56 * @param TermsOfService $termsOfService 57 */ 58 public function SetTerms($termsOfService); 59 60 /** 61 * @param bool $accepted 62 */ 63 public function SetTermsAccepted($accepted); 64} 65 66abstract class ReservationPage extends Page implements IReservationPage 67{ 68 protected $presenter; 69 protected $available = true; 70 71 /** 72 * @var PermissionServiceFactory 73 */ 74 protected $permissionServiceFactory; 75 76 public function __construct($title = null) 77 { 78 parent::__construct($title); 79 80 if (is_null($this->permissionServiceFactory)) 81 { 82 $this->permissionServiceFactory = new PermissionServiceFactory(); 83 } 84 } 85 86 /** 87 * @return IReservationPresenter 88 */ 89 protected abstract function GetPresenter(); 90 91 /** 92 * @return string 93 */ 94 protected abstract function GetTemplateName(); 95 96 /** 97 * @return string 98 */ 99 protected abstract function GetReservationAction(); 100 101 public function PageLoad() 102 { 103 $this->presenter = $this->GetPresenter(); 104 $this->presenter->PageLoad(); 105 106 $this->Set('ReturnUrl', $this->GetReturnUrl()); 107 $this->Set('ReservationAction', $this->GetReservationAction()); 108 $this->Set('MaxUploadSize', UploadedFile::GetMaxSize()); 109 $this->Set('MaxUploadCount', UploadedFile::GetMaxUploadCount()); 110 $this->Set('RepeatEveryOptions', range(1, 20)); 111 112 if ($this->IsUnavailable()) 113 { 114 $this->RedirectToError(ErrorMessages::RESERVATION_NOT_AVAILABLE); 115 return; 116 } 117 118 $this->Display($this->GetTemplateName()); 119 } 120 121 public function BindAvailableResources($resources) 122 { 123 $this->Set('AvailableResources', $resources); 124 } 125 126 public function SetReservationResource($resource) 127 { 128 $this->Set('ResourceName', $resource->GetName()); 129 $this->Set('ResourceId', $resource->GetId()); 130 $this->Set('Resource', $resource); 131 } 132 133 public function ShowReservationDetails($showReservationDetails) 134 { 135 $this->Set('ShowReservationDetails', $showReservationDetails); 136 } 137 138 public function HideRecurrence($isHidden) 139 { 140 $this->Set('HideRecurrence', $isHidden); 141 } 142 143 protected function GetReturnUrl() 144 { 145 $redirect = $this->GetQuerystring(QueryStringKeys::REDIRECT); 146 if (!empty($redirect)) 147 { 148 return $redirect; 149 } 150 return $this->GetLastPage(Pages::SCHEDULE); 151 } 152 153 protected function LoadInitializerFactory() 154 { 155 $userRepository = new UserRepository(); 156 return new ReservationInitializerFactory( 157 new ScheduleRepository(), $userRepository, new ResourceService(new ResourceRepository(), 158 $this->permissionServiceFactory->GetPermissionService(), 159 new AttributeService(new AttributeRepository()), 160 $userRepository, 161 new AccessoryRepository()), 162 new ReservationAuthorization(AuthorizationServiceFactory::GetAuthorizationService()) 163 ); 164 } 165 166 public function SetAvailability(DateRange $availability) 167 { 168 $this->Set('AvailabilityStart', $availability->GetBegin()); 169 $this->Set('AvailabilityEnd', $availability->GetEnd()); 170 } 171 172 public function SetTerms($termsOfService) 173 { 174 $this->Set('Terms', $termsOfService); 175 } 176}
create.tpl (画面テンプレート)
ダメ元で追加してみた(もちろん表示されなかった)
該当する tpl_cファイル を削除して再生成しても同様。。。
php
1<p> 2 { $Testtest } 3</p>
画面出力確認結果
HTML
1<p> 2 3</p>
↑ pタグは出てるけどセットしたはずの Testtest は出力されなかった
ざっくりしすぎてるのでダメ元で質問させていただいてます。。。
smartyとやらも使われてるらしく、どこかに記述が足りないんじゃないかとは思うのですが中々見つけられず・・・。
お時間ある方で、tplファイルにPHPからデータ渡したことある方や、
お気づきの点ある方いらっしゃいましたらご助力頂けますと幸いです。。。
足りない情報等あればお申し付け下さい。
回答2件
あなたの回答
tips
プレビュー