CakePHP3で、数値を金額フォーマットにして表示する処理を作成しました。
php
1$price = 10000; 2echo $this->Number->format($price) . " 円"; 3
テンプレート内に記述しているときは問題なく表示されていました。
ですが、他の処理でも流用できるよう下記の様なヘルパーを作成しました。
(実際のヘルパーではいくつかの処理を追加していますが。)
php
1<?php 2namespace App\View\Helper; 3 4use Cake\View\Helper; 5use Cake\View\View; 6 7class CommonHelper extends Helper 8{ 9 protected $_defaultConfig = []; 10 11 public function getMakerPrice($price = 0) 12 { 13 $priceText = ( $this->Number->format($price) ) . " 円"; 14 return $priceText; 15 } 16 17} 18
ですが、下記のエラーが発生しました。
Call to a member function format() on null
下記なども試して見たのですが、エラーは解消しませんでした。
php
1Number::format($price); 2$this->Number::format($price); 3$this->Helper->Number::format($price)
$this->Number->format()の呼び出し方が違っているのであろうとは思っておりますが、どのように記述すればいいものでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/16 05:19