Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //###### user.phtml ######//
- <?php if(!empty($this->username)){ echo $this->username,'<br />';} ?>
- <p>User Form</p>
- <form action="/user/newuser" method="post">
- <input type="text" name="newuser" /><br />
- <input type="submit" value="submit" /><br />
- </form>
- <p>This page has <?php echo $this->view->count;?> form fields.</p>
- //###### end ######//
- //###### FormfieldCounter.php ######// <?php
- // file: application/action/helpers/FormfieldCounter.php
- class Phpa_Controller_Action_Helper_FormfieldCounter
- extends Zend_Controller_Action_Helper_Abstract
- {
- public function count($template)
- {
- $dom = new Zend_Dom_Query($template);
- $query = $dom->query('input[type="text"]');
- return count($query);
- }
- }
- /*// I suspect that this is supposed to be in the controller. We'll see ...
- public function newUserAction()
- {
- // action body
- $formfieldCounter = $this->_helper->getHelper('FormfieldCounter');
- $count = $formfieldCounter->count(
- $this->view->render('users/new-user.phtml'));
- $this->view->count = $count;
- }*/
- ?> //###### end ######//
- //###### USerController.php ######// <?php
- class UserController extends Zend_Controller_Action
- {
- public function init(){
- }
- public function indexAction(){
- }
- private function viewAction($var = null) {// renders via the /views/scripts/user/user.phtml template
- $var = $var? $var: 'user';
- $this->render($var);
- }
- public function __call($method,$args) {
- // $method is the method name (whose name contains 'Action')
- $username=ucwords(substr($method,0, -6)); // so we remove 'Action' from the end
- $this->view->username=$username;
- $this->viewAction();
- }
- /*public function newuserAction() {// renders application/views/scripts/user/user.phtml
- $payload = $this->getRequest()->getPost();
- $this->view->username = $payload['newuser'];
- $this->viewAction();
- }*/
- public function newuserAction(){ // this is a copy/paste from pastebin.com/XeBEaQ0h
- $formfieldCounter = $this->_helper->getHelper('FormfieldCounter');
- $count = $formfieldCounter->count( $this->view->render('users/new-user.phtml'));
- $this->view->count = $count;
- }
- public function newuserdataAction() {// renders application/views/scripts/user/user.phtml
- $payload = $this->getRequest()->getPost();
- $this->view->username = $payload['newuser'];
- $this->viewAction();
- }
- }
- ?> //###### end ######//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement