Advertisement
mOrloff

Untitled

Jun 18th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. //###### user.phtml ######//
  2. <?php if(!empty($this->username)){ echo $this->username,'<br />';} ?>
  3. <p>User Form</p>
  4. <form action="/user/newuser" method="post">
  5.     <input type="text" name="newuser" /><br />
  6.     <input type="submit" value="submit" /><br />
  7. </form>
  8. <p>This page has <?php echo $this->view->count;?> form fields.</p>
  9. //###### end ######//
  10.  
  11.  
  12. //###### FormfieldCounter.php ######// <?php
  13. // file: application/action/helpers/FormfieldCounter.php
  14. class Phpa_Controller_Action_Helper_FormfieldCounter
  15.     extends Zend_Controller_Action_Helper_Abstract
  16. {
  17.     public function count($template)
  18.     {
  19.         $dom = new Zend_Dom_Query($template);
  20.         $query = $dom->query('input[type="text"]');
  21.         return count($query);
  22.     }
  23. }
  24. /*// I suspect that this is supposed to be in the controller. We'll see ...
  25. public function newUserAction()
  26. {
  27.     // action body
  28.     $formfieldCounter = $this->_helper->getHelper('FormfieldCounter');
  29.     $count = $formfieldCounter->count(
  30.         $this->view->render('users/new-user.phtml'));
  31.     $this->view->count = $count;
  32. }*/
  33. ?> //###### end ######//
  34.  
  35.  
  36. //###### USerController.php ######// <?php
  37. class UserController extends Zend_Controller_Action
  38. {
  39.     public function init(){
  40.     }
  41.     public function indexAction(){
  42.     }
  43.     private function viewAction($var = null) {// renders via the /views/scripts/user/user.phtml template
  44.         $var = $var? $var: 'user';
  45.         $this->render($var);
  46.     }
  47.     public function __call($method,$args) {
  48.         // $method is the method name (whose name contains 'Action')
  49.         $username=ucwords(substr($method,0, -6));  // so we remove 'Action' from the end
  50.         $this->view->username=$username;
  51.         $this->viewAction();
  52.     }
  53.     /*public function newuserAction() {// renders application/views/scripts/user/user.phtml
  54.         $payload = $this->getRequest()->getPost();
  55.         $this->view->username = $payload['newuser'];
  56.         $this->viewAction();
  57.     }*/
  58.     public function newuserAction(){  // this is a copy/paste from pastebin.com/XeBEaQ0h
  59.         $formfieldCounter = $this->_helper->getHelper('FormfieldCounter');
  60.         $count = $formfieldCounter->count( $this->view->render('users/new-user.phtml'));
  61.         $this->view->count = $count;
  62.     }
  63.     public function newuserdataAction() {// renders application/views/scripts/user/user.phtml
  64.         $payload = $this->getRequest()->getPost();
  65.         $this->view->username = $payload['newuser'];
  66.         $this->viewAction();
  67.     }
  68. }
  69. ?> //###### end ######//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement