Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
48
Help us understand the problem. What is going on with this article?
@hokutoasari

FuelPHP で自作関数みたいなファイルはどこに置いたら良いか

More than 5 years have passed since last update.

FuelPHP で自作関数みたいなファイルはどこに置いたら良いか

答え:./fuel/app/classes/ 以下にルールに従って配置する。

/fuel/app/classes/hoge.php
<?php
class Hoge {
    public static function fuga($var)
    {
        return $var . ' fuga.';
    }
}

みたいに置く。
このように置いておくと、普通に使えるようになる。

/fuel/app/classes/controller/welcome.php
<?php
class Controller_Welcome extends Controller
{
    public function action_index()
    {
        $fuga = Hoge::fuga('This is');// This is fuga.
        return Response::forge(View::forge('welcome/index'));
    }
}

みたいに。

階層を持った置き方

./classes 直下に置くとごちゃごちゃして嫌だとか。
そんな時はルールに従えばOK。(たぶん…)
例えば、以下みたいにしてみるとか。

/fuel/app/classes/myutil/validation.php
<?php
class MyUtil_Validation {
    public static function validateHoge($string) {
        return $string . ' hoge';
    }
    public static function validateFuga($string) {
        return $string . ' fuga';
    }
    public static function _validation_is_unique($val, $field)
    {
        $flag = false;
        // ゴニョゴニョ
        return $flag;
    }
}

これで、MyUtilディレクトリの中にいろいろ入れれそうな気がする。

複数階層に渡る場合は、ディレクトリセパレーターとして「_」を用いてクラス名をつけてやればいい。(はず…)

48
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
48
Help us understand the problem. What is going on with this article?