thinkphp常量調用

來源:互聯網
上載者:User
在Action中如何調用model中的常量,比如systemAciton.class.php 中的方法想調用memberModel.class.php中的const DEFAULT_STATUS=1這個變數的值,能調用到嗎?求解!(希望是親測成功再回答!謝謝!)


回複討論(解決方案)

memberModel::DEFAULT_STATUS;

memberModel::DEFAULT_STATUS; 這樣子試過,tp會報錯,不知道什麼情況!


memberModel::DEFAULT_STATUS; 這樣子試過,tp會報錯,不知道什麼情況!
報什麼錯? 這個是php調用常量的方法。

這樣調用TP沒報錯的路過



memberModel::DEFAULT_STATUS; 這樣子試過,tp會報錯,不知道什麼情況!
報什麼錯? 這個是php調用常量的方法。 這是我的引用:
$model = D('Member');
echo $model::USER_STATUS;
exit;
報錯:syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' E:\www\xxx.xxx.com\xxx\Lib\Action\FbadminAction.class.php 第 76 行.

您的php版本太低了,至少要php5.3才可以這樣用




memberModel::DEFAULT_STATUS; 這樣子試過,tp會報錯,不知道什麼情況!
報什麼錯? 這個是php調用常量的方法。 這是我的引用:
$model = D('Member');
echo $model::USER_STATUS;
exit;
報錯:syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' E:\www\xxx.xxx.com\xxx\Lib\Action\FbadminAction.class.php 第 76 行. 不用實現化模型,::是PHP的文法。MemberModel::USER_STATUS直接調用常量。

您的php版本太低了,至少要php5.3才可以這樣用 哦 然來是這個情況!謝謝你了!





memberModel::DEFAULT_STATUS; 這樣子試過,tp會報錯,不知道什麼情況!
報什麼錯? 這個是php調用常量的方法。 這是我的引用:
$model = D('Member');
echo $model::USER_STATUS;
exit;
報錯:syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' E:\www\xxx.xxx.com\xxx\Lib\Action\FbadminAction.class.php 第 76 行. 不用實現化模型,::是PHP的文法。MemberModel::USER_STATUS直接調用常量。 原來要這樣子才行啊!謝謝你拉!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.