「Php/codeigniter/library」の版間の差分
ナビゲーションに移動
検索に移動
| 17行目: | 17行目: | ||
{ | { | ||
// メソッドの処理 | // メソッドの処理 | ||
return 'Result: ' . $param; | return 'Result: ' . print_r($param,1); | ||
} | } | ||
} | } | ||
2025年5月15日 (木) 16:30時点における版
ライブラリの使い方
application/libraries/ディレクトリに新しいライブラリファイルを作成する
application/libraries/Mylibrary.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mylibrary {
public function __construct()
{
// コンストラクタ
}
public function my_method($param = '')
{
// メソッドの処理
return 'Result: ' . print_r($param,1);
}
}
ライブラリの呼び出し方
$this->load->library('mylibrary'); // ここは小文字になる
echo $this->mylibrary->my_method('parameter');
初期化パラメータを渡す場合
$params = array('param1' => 'value1', 'param2' => 'value2');
$this->load->library('mylibrary', $params);
ライブラリクラス側
public function __construct($params)
{
// $paramsを処理
}