Unsupported operand types when call _getAllParams()
December 31, 2006 on 2:40 pm | In Zend Framework | 6 CommentsI 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
-
$this->_getAllParams();
-
-
I got the error message as "unsupported operand types".
Finally, I found the problem in Zend\Controller\Request\Http.php line 601
-
590 /**
-
591 * Retrieve an array of parameters
-
592 *
-
593 * Retrieves a merged array of parameters, with precedence of userland
-
594 * params (see {@link setParam()}), $_GET, $POST (i.e., values in the
-
595 * userland params will take precedence over all others).
-
596 *
-
597 * @return array
-
598 */
-
599 public function getParams()
-
600 {
-
601 return $this->_params + $_GET + $_POST;
-
602 }
-
The reason is because $_GET and/or $_POST was NULL when getParams() was called.
Temporarily , I changed it as below:
-
public function getParams()
-
{
-
-
if ( null !== $_GET && null !== $_POST) {
-
return $this->_params + $_GET + $_POST;
-
} elseif ( null !== $_GET && null == $_POST) {
-
return $this->_params + $_GET;
-
} elseif ( null == $_GET && null !== $_POST) {
-
return $this->_params + $_POST;
-
}
-
return $this->_params;
-
}
Refactor-Step One
December 31, 2006 on 2:14 am | In Zend Framework | No CommentsBy 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
-
-
class FormController extends Zend_Controller_Action
-
-
{
-
function init()
-
{
-
Zend::loadClass(‘Bookmark’);
-
Zend::loadClass(‘User’);
-
}
-
public function insertAction()
-
{
-
-
$arg1 = $this->_request->getParam(‘arg1_name’, 0);
-
$args = $this->_request->getParams();
-
…
-
}
-
}
-
in IndexController.php, the code would be
-
function addAction()
-
{
-
$data = array
-
(
-
‘arg1_name’ => ‘arg1′,
-
‘arg2_name’ => ‘arg2′,
-
‘arg3_name’ => ‘arg3′
-
);
-
-
$this->_forward(‘form’,‘insert’,$data);
-
}
Zend Framework could not recognize index.php
December 22, 2006 on 9:40 am | In Zend Framework | 2 CommentsIn 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 CommentsSince 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 CommentWaiting 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
-
$controller->setBaseUrl($baseUrl);
instead of
-
$router->setRewriteBase($baseUrl);
-
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.
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^