Ich entschuldige mich dafür, dass ich den Fragetitel nicht korrekt eingerahmt habe. ich auf Skelett Anwendung von ZF3 arbeite acl.I umsetzen konnte sich nicht wie die Reihe der entsprechenden E-Mail address.I abzurufen haben zwei Controller AlbumController.php und LoginController.php AlbumController.phpSo rufen Sie eine Methode des Modells vom Controller im Zend Framework 3 auf
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;
}
I getRow() -Methode von LoginTable.php in Modell LoginTable.php nenne. Aber es wirft einen Fehler Anruf auf eine Elementfunktion getRow() auf einem Nicht-Objekt
LoginTable.php
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 Danke für die Info.Ich habe es mit Sitzungsvariable –
@AI Fonce können Sie mir sagen, wo kann ich diese Fabrik erstellen und wie kann ich diese Fabrik anrufen? –
@AzharAhmad Ihre Antwort ist in der offiziellen Dokumentation: lesen Sie es https://docs.zendframework.com/tutorials/in-depth-guide/models-and-servicemanager/#writing-a-factory-class –