Method on controller not being called
Permalink
Hi.
I'm creating a block to perform "registration code" lookup for our customers.
I've the following view:
And the following controller:
But it appears that the method is never called. The action URL appears to be setup in the form submit (it's inside the generated HTML). If I override the view() method, then it's called - just not the action method.
If I simply replace all the controller code with something that sets a known variable in the view (such as $answer), it never shows - which seems to indicate it's not being called. If I shift the code that sets $answer into the view() method, then it does get called and it does show in the view.
I feel like I must be doing something trivially wrong - but from what I can tell I'm following the examples set down.
Ideas anyone?
I'm creating a block to perform "registration code" lookup for our customers.
I've the following view:
<ul class="boxed"> <li class="one"><h3><?php echo $blockHeading?></h3></li> <div> <p>Email address:</p> <form method="post" action="<?=$this->action('lookupcode')?>" style="display: block;"> <input type="text" name="email" size="25"/> <input type="submit" value="Find..."/> </form> <?php if($this->controller->getTask() == "find_code") { if($answer) { echo "<p>$answer</p>"; } else { echo "..."; } } ?> </div> </ul>
And the following controller:
public function lookupcode() { $dbHost = $this->dbHost; $dbUser = $this->dbUser; $dbPass = $this->dbPwd; $dbToUse = $this->dbDefault; $this->db = null; $this->db = mysql_connect($dbHost, $dbUser, $dbPass); ... ... ...
But it appears that the method is never called. The action URL appears to be setup in the form submit (it's inside the generated HTML). If I override the view() method, then it's called - just not the action method.
If I simply replace all the controller code with something that sets a known variable in the view (such as $answer), it never shows - which seems to indicate it's not being called. If I shift the code that sets $answer into the view() method, then it does get called and it does show in the view.
I feel like I must be doing something trivially wrong - but from what I can tell I'm following the examples set down.
Ideas anyone?
Old post, I know, but in case anyone was wondering, I think the function is supposed to be:
I have the same issue.
$this->action('validate') is generating what looks like a correct URL:
http://www.myfakedomain.com/samsung3d/index.php?cID=1&bID=42&am...
And in my Block's controller.php I have
public function action_validate() {
...
}
It just appears to be calling view().
Any ideas?
Cheers
Russell
$this->action('validate') is generating what looks like a correct URL:
http://www.myfakedomain.com/samsung3d/index.php?cID=1&bID=42&am...
And in my Block's controller.php I have
public function action_validate() {
...
}
It just appears to be calling view().
Any ideas?
Cheers
Russell
Yes, I battled with this one for a while...
I'm not sure what's going on exactly, but it seems like this only works with single pages. Couldn't get it to work in a block. I think you need to do it the other way around to get it to work in a block. Can't remember precisely what I did, but it felt wrong yet worked! :S
Try your function just as 'public function validate()'
Jon
I'm not sure what's going on exactly, but it seems like this only works with single pages. Couldn't get it to work in a block. I think you need to do it the other way around to get it to work in a block. Can't remember precisely what I did, but it felt wrong yet worked! :S
Try your function just as 'public function validate()'
Jon
Ignore me - I checked - calling $this->action('validate'); inside a blocks view should run the method action_validate() in the blocks controller.
It didn't work for me when I was trying to use Zend Form. I was trying to say $form->setAction($this->action('mymethod')); but although the html looked perfect, it didn't work :S
When I manually entered the form tag and typed action="<?php echo $this->action('mymethod') ?>" it worked fine.
Does that help at all??
Jon
It didn't work for me when I was trying to use Zend Form. I was trying to say $form->setAction($this->action('mymethod')); but although the html looked perfect, it didn't work :S
When I manually entered the form tag and typed action="<?php echo $this->action('mymethod') ?>" it worked fine.
Does that help at all??
Jon
Hi,
Yes try
public function validate(), the function name should be same.
Yes try
public function validate(), the function name should be same.
No, it's only the same when calling a method from a link.
When using $this->action('methodname') you need to call the method 'action_methodname'
Jon
When using $this->action('methodname') you need to call the method 'action_methodname'
Jon
Hi Jon,
Thanks for the info
Thanks for the info