質問のタイトルを正確にフレーミングしていないことをお詫び申し上げます。私は電子メールaddress.Iの対応の行を取得する方法を見つけ出すことができませんでしたacl.Iを実装するためにZF3のスケルトンアプリケーションに取り組んでいます は二つのコントローラAlbumController.phpとLoginController.php AlbumController.phpZend Framework 3のコントローラからモデルのメソッドを呼び出す方法
private $table;
public function __construct(AlbumTable $table)
{
$this->table = $table;
}
public function deleteAction()
{
$user_session=new Container('user');
if(isset($user_session->email))
{
$row=$this->loginTable->getRow($user_session->email);//*Here is the problem*
if($row['role']=='admin')
{
$acl=new Acl();
if($acl->isAllowed('admin','AlbumController','delete'))
{
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('album');
}
$request = $this->getRequest();
if ($request->isPost()) {
$del = $request->getPost('del', 'No');
if ($del == 'Yes') {
$id = (int) $request->getPost('id');
$this->table->deleteAlbum($id);
}
return $this->redirect()->toRoute('album');
}
return [
'id' => $id,
'album' => $this->table->getAlbum($id),
];
}
}
return $this->redirect()->toRoute('login');
}
}
を持っています
LoginController.php
public $user_session;
public $loginTable;
public function __construct(LoginTable $loginTable)
{
$this->loginTable = $loginTable;
}
私はモデル LoginTable.phpでLoginTable.phpの存在の場合のgetRow()メソッドを呼び出しています。しかし、それはあなたがあなたのAlbumControllerクラスの$this->loginTable->getRow()
を呼び出しているが、あなたは」didnの非オブジェクト
LoginTable.php
上)メンバ関数のgetRow(へclass LoginTable
{
protected $tableGateway;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function getRow($mail)
{
$email = $mail;
$rowset = $this->tableGateway->select(array('email' => $email));
$row = $rowset->current();
if (!$row) {
throw new \Exception("Could not find row $email");
}
return $row;
}
@AI Fonce Thanx for this info.Iセッション変数を使用しています。 –
@AI Fonceは、この工場をどこで作成できますか、どのようにこの工場を呼び出すことができますか? –
@AzharAhmadあなたの答えは公式の文書にあります:https://docs.zendframework.com/tutorials/in-depth-guide/models-and-servicemanager/#writing-a-factory-class –