HI Nlissau,
Are you able to access any helpers via getHelper or is it only the
FlashMessenger that is giving you trouble? I'm also not sure if the
getHelper string is case sensitive, but you have a lowercase M in
$this->view->messages=$this->getHelper('Flashmessenger')->getMessages();
Which may/may not be causing your issue...
Can you paste your call-stack var_dump(debug_backtrace());
The code on line 299 of the helper broker is... if (null ===
($actionController = $helper->getActionController())) {
Which would seem to imply that $helper is null... which is likely due to
the name not being correct.
--
Kevin McArthur
P.S. Hope you enjoy the book ;)
On 11-03-04 01:25 PM, Nlissau wrote:
Hi.
I just recently started learning the Zend Framework and bought an excellent
book: "pro php" by Kevin McArthur. I have been following a lot of the
examples there are in the book, but there is one example that doesn't seem
to work properly.
The error I get is:
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
The error is this line of code: (when I remove it, there is no error :))
$this->getHelper('FlashMessenger')->addMessage($field . ' : '. $message);
I hope you can help me out,
Nicolai
The example is listing 15-16 (if someone has the book):
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();
}
}
}
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Error-on-non-object-Pro-PHP-book-tp3335964p3335964.html
Sent from the Zend Framework mailing list archive at Nabble.com.