在我的 Zend Framework 2 项目中,我有一个外部库,我想将我的信息与模型一起保存在基础中。
……………………
编辑信息:
我再次解释了我的需求:在我的控制器中,我在数据库中进行插入和删除,并且我想将所有操作记录在“t_log”表中。为此,我想创建一个外部类。
我的问题是:如何从外部类调用模型方法?
namespace Mynamespace;
use Firewall\Model\Logs;
use Firewall\Model\LogsTable;
class StockLog
{
public function addLog()
{
$log = $this->getServiceLocator()->get('Firewall\Model\LogTable');
$log->save('user added');
die('OK');
}
}
我的模型:
namespace Firewall\Model;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Select;
class UserGroupTable
{
protected $tableGateway;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function save()
{
// How I Can call this method from the StockLog method ?
}
}
谢谢 !