我在 stackoverflow 上阅读了其他一些关于将参数传递给类库的帖子(例如,如何将多个参数传递给 CodeIgniter 中的库?),我还阅读了库部分下的用户手册。
我想知道是否可以将参数作为单个变量而不是数组传递?
我的课程——我想在我的 codeigniter 解决方案之外使用——看起来像这样:
<?php
class ABC
{
private $_hostname;
private $_password;
private $_username;
private $_connection;
private $_data;
private $_timeout;
private $_prompt;
public function __construct($hostname, $password, $username = "", $timeout = 10)
{
set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/phpseclib');
include('Net/SSH2.php');
$this->_hostname = $hostname;
$this->_password = $password;
$this->_username = $username;
} // __construct
public function connect()
{
}
public function dosomething()
{
}
我知道我可以做类似的事情:
$params = array('_hostname' => $ip, '_password' => 'password', '_username' => '');
$this->load->library($classname,$params );
但我不想使用数组,因为此类将被非 CI 解决方案重用。我尝试恢复使用标准的 include() 语句。所以代码看起来像:
set_include_path(get_include_path() . PATH_SEPARATOR . 'var/www/myCIapp/application/libraries');
include_once('libraries/'.$classname.'.php');
但它抱怨说它找不到包含文件。具体消息是:
遇到 PHP 错误
严重性:警告
消息:include_once() [function.include]:无法打开“libraries/HP5406_ssh.php”以包含(include_path='.:/usr/share/php:/usr/share/pear:var/www/myCIapp/application/图书馆/')
文件名:models/ss_model.php
行号:88
任何建议,将不胜感激。谢谢阅读...