私はcodeigniterにロードしたい静的関数のクラス(共通のユーティリティ関数)を持っています。現在、通常はinclude_once(...)
を使用してロードしていますが、期待どおりに動作します。CodeIgniter:自分のクラスの静的関数をコントローラにロードする方法は?
ただし、codeigniterの方法論を使用して読み込みたいとします。クラスファイルをthird_partyディレクトリに保存する必要があることを理解しています。私はクラスを必要とするライブラリクラス(ライブラリディレクトリに保存する)を作成する必要があります。
以下は3つのコンポーネントですが、動作しません。
// saved at: APPPATH.'libraries/Library_Wrapper.php'
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Library_Wrapper
{
public function __construct()
{
require_once APPPATH.'third_party/My_Class.php';
}
}
3: -
// my class, saved at: APPPATH.'third_party/My_Class.php'
class My_Class
{
public static function my_static_utility_method ()
{
return "booger" ;
}
// ...
}
私は '図書館' のインスタンスのCIの規則に従うラッパーを作成することになっていますということを理解します -今、私はcontrからMy_Classの静的メソッドにアクセスしたいoller:
// saved at: APPPATH.'controllers/my_controller.php'
class My_Controller extends CI_Controller
{
public function __constructor()
{
parent::__construct();
$this->load->library('Library_Wrapper') ;
}
public function some_function()
{
echo $this->My_Class->my_static_utility_method() ;
}
}
CI3を使用していて、クラスの最初の文字とコントローラのファイル名を適用する必要がある場合は、こちらをご覧ください。http://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello -world – user4419336
私は大文字が実際に本当の機能的効果を持っているとは思わない? – dsdsdsdsd
@dsdsdsdsd - それはあなたの仕事ですか? –