Unsupported operand types when call _getAllParams()

December 31, 2006 on 2:40 pm | In Zend Framework | 6 Comments

I think it is a bug, however, it seems that I can’t login into Zend Framework Wiki today. Anyway, here is what I have found.

When I call _getAllParams() in FormController, like

Code (php)
  1. $this->_getAllParams();
  2.  
  3.  

I got the error message as "unsupported operand types".

Finally, I found the problem in Zend\Controller\Request\Http.php   line 601

Code (php)
  1.   590   /**
  2.   591    * Retrieve an array of parameters
  3.   592   *
  4.   593    * Retrieves a merged array of parameters, with precedence of userland
  5.   594    * params (see {@link setParam()}), $_GET, $POST (i.e., values in the
  6.   595    * userland params will take precedence over all others).
  7.   596    *
  8.   597    * @return array
  9.   598    */
  10.   599    public function getParams()
  11.   600    {
  12.   601            return $this->_params + $_GET + $_POST;
  13.   602    }
  14.  

The reason is because $_GET and/or $_POST was NULL when getParams() was called.

Temporarily , I changed it as below:

Code (php)
  1. public function getParams()
  2. {
  3.  
  4.           if ( null !== $_GET && null !== $_POST) {
  5.                  return $this->_params + $_GET + $_POST;
  6.           } elseif ( null !== $_GET && null == $_POST) {
  7.                 return $this->_params + $_GET;
  8.           } elseif ( null == $_GET && null !== $_POST) {
  9.                 return $this->_params + $_POST;
  10.           }
  11.                 return $this->_params;
  12. }

Refactor-Step One

December 31, 2006 on 2:14 am | In Zend Framework | No Comments

By now, my  first  step of refactor for addAction(), editAction() etc. has been finished. They are all related FORM operation. First of all, I created a form controller which named FormController. Of course, the file name is FormController.php and the class name is FormController().

It looks like

Code (php)
  1.  
  2. class FormController extends Zend_Controller_Action
  3.  
  4. {
  5.    function init()
  6.    {
  7.     Zend::loadClass(‘Bookmark’);
  8.     Zend::loadClass(‘User’);
  9.    }
  10.    public function insertAction()
  11.    {
  12.  
  13.           $arg1  = $this->_request->getParam(‘arg1_name’, 0);
  14.           $args  = $this->_request->getParams();
  15.           …
  16.    }
  17. }
  18.  

in IndexController.php, the code would be

Code (php)
  1. function addAction()
  2. {              
  3.    $data = array
  4.    (   
  5.         ‘arg1_name’   => ‘arg1′,
  6.         ‘arg2_name’   => ‘arg2′,
  7.         ‘arg3_name’   => ‘arg3′
  8.    );
  9.        
  10.    $this->_forward(‘form’,‘insert’,$data);
  11. }

Zend Framework could not recognize index.php

December 22, 2006 on 9:40 am | In Zend Framework | 2 Comments

In RewriteRouter.php, after line 136 add

/** Added by Jason Qi Nov 28, 2006 */
        $tpath = $path;
        $tpath = strtolower($tpath);
        if (strstr($tpath, ‘.php’)) {
            $path = substr($path, 0, strpos($path, ‘.’));
        }

to eliminate .php from index.php

File structure - redesign

December 22, 2006 on 9:40 am | In Zend Framework | No Comments

Since I develop my tutorial based on Rob Allen’s. I changed my file structure as follow:

/application
  /controller
  /model
  /view
    /smarty
      /templates

/library
  /Zend
  /Bkdiy
    /View
     /smarty
     /smarty_config
    Smarty.php
  Zend.php
/tmp                                 /* updated by December 22, 2006 */
  /smarty_cache
  /smarty_compile

/public
index.php
.htaccess

Refactor!

December 19, 2006 on 9:19 pm | In Zend Framework | 1 Comment

Waiting is boring, but I have to wait, I am waiting for Zend_Auth, I am waiting for Rob’s update because Version 0.6.0 chnaged Zend_Controller a lot.

So far I just use

Code (php)
  1. $controller->setBaseUrl($baseUrl);

instead of

Code (php)
  1. $router->setRewriteBase($baseUrl);
  2.  

in index.php
But, The _action property is no longer set. … Anyway, Rob’s is going to update his tutorial soon. It is better not repeating this job. let me do something else!  Do you still remember these in Rob’s tutorial?

Refactor!
It shouldn’t have escaped your notice that AddAction() and EditAction() are very similar and
that the add and edit templates are identical. Some refactoring is in order!
I’ve left it as an exercise for you, dear reader…

As a matter of fact, not only addAction() and editAction, but manys other actions would do the similar behavior. As far as I know is registerAction() which I will add into my project.

So it is time to think about it. I’d like to develop some models named Bkadd.php Bkupdate.php etc, they will handle all actions that related to add/update one record to table.

Next Page »
Since May 6,2007 We have Visitors
dog ramps

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^