[fw-general] Re: Error on 'non-object'? (Pro PHP book)

2011-03-06 Thread Nlissau
Thank you for the quick response. I can't believe it. I've been through that
code maybe a hundred times, being sure that the problem was the line I
posted. But the change of the m-M did the job :)

Thank you!

And by the way it is a really well written book. Made me change the way I do
scripting and made me explore the Zend Framework :) I'm gonna try to include
Smarty tomorrow :)

--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Error-on-non-object-Pro-PHP-book-tp3335964p3336105.html
Sent from the Zend Framework mailing list archive at Nabble.com.


[fw-general] Error on 'non-object'? (Pro PHP book)

2011-03-04 Thread Nlissau
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.