Zend: Fejl med non-object?
Hej eksperter.Jeg har en klasse jeg ikke kan få til at fungere. Når jeg prøver at køre den får jeg fejlen:
Fatal error: Call to a member function getActionController() on a non-object in C:\wamp\bin\php\ZendFramework\ZendFramework-1.11.3\library\Zend\Controller\Action\HelperBroker.php on line 299
Jeg har fundet ud af at det er linjen herunder der volder problemer, men kan ikke gennemskue hvor fejlen ligger:
$this->getHelper('FlashMessenger')->addMessage($field . ' : '. $message);
Håber I er lidt skarpere ;) På forhånd tak.
Her er min kode: (fra bogen pro php)
class CustomersController extends Zend_Controller_Action {
public function indexAction() {
$table = new Customers(); // Må så tage my model Customers (from application/models/Customers.php)
$this->view->customers = $table->fetchAll();
}
public function redirectasAction() {
$this->getHelper('redirector')->goto('index');
}
public function redirectAction() {
$this->getHelper('FlashMessenger')->addMessage("This was set at the redirector");
$this->getHelper('redirector')->goto('show');
}
public function showAction() {
$this->view->messages = $this->getHelper('FlashMessenger')->getMessages();
}
public function addAction() {
Zend_Debug::dump($this->getRequest()->getPost());
$request = $this->getRequest();
//Deterine if processing a post request
if($request->isPost()) {
//Filter tags from the name field
$filters = array(
'name' => 'StripTags'
);
//Validate name is not less than 1 character and not more than 64
$validation = array(
'name' => array (
array(
'StringLength', 1, 64)
)
);
//Initialize Zend_Filter_input passing it the entire getPost() array
$zfi = new Zend_Filter_Input($filters, $validation, $request->getPost());
//If the validators passed this will be true
if($zfi->isValid()) {
//Fetch the data from zfi directly and create an array for Zend_Db
$clean = array();
$clean['name'] = $zfi->name;
//Create an instance of the customers table and insert the $clean row
$customers = new Customers();
$customers->insert($clean);
//Redirect to the display page after adding
$this->getHelper('redirector')->goto('index');
} else {
// The form didn't validate, get the messages from ZFI
foreach($zfi->getMessages() as $field=>$messages) {
//Put each ZFI message into the FlashMessenger so it shows on the form
foreach($messages as $message) {
$this->getHelper('FlashMessenger')->addMessage($field . ' : '. $message);
}
}
$this->getHelper('redirector')->goto('add');
}
}
// not a post request, check for flash messages and expose to the view
if($this->getHelper('FlashMessenger')->hasMessages()) {
$this->view->messages=$this->getHelper('Flashmessenger')->getMessages();
}
}
}