Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2008, 03:20 PM
Junior Member
 
Join Date: Mar 2008
Posts: 6
Default Custom Form Element with custom ViewHelper

I would like to create a custom Form Element which is essentially a Textarea with some javascript to turn it into a WYSIWYG editor (using NicEditor). I thought the best way to do this would be would be something like this

PHP Code:
class Foo_View_Helper_FormNicEditor extends Zend_View_Helper_FormTextarea
{
    public function 
formNicEditor($name$value$value null$attribs null)
    {
         
$textarea $this->formTextarea($name$value$attribs);
         return ..........
    } 
   

and then in my custom Form Element to set
PHP Code:
pubic $helper 'formNicEditor' 
...the problem of course being that it doesn't know where to find this ViewHelper.

What I settled on do was overwriting the render method as follows:

PHP Code:
public function render(Zend_View_Interface $view null
{
         
$view $this->getView();
         
$view->setHelperPath('Foo/View/Helper''Chintion_View_Helper');
         return 
parent::render($view);

This works, but it doesn't feel right to me...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-08-2008, 05:59 PM
Junior Member
 
Join Date: Apr 2008
Posts: 8
Default

you can set setHelperPath() whereever in the code. for example you can execute it in the action method where it will be used.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-09-2008, 03:02 PM
Junior Member
 
Join Date: Mar 2008
Posts: 6
Default

True, but I would prefer that the element live "self-sufficiently"...I want the element to be ready to be used anywhere in my application (and in any other application).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-09-2008, 08:42 PM
Junior Member
 
Join Date: Oct 2007
Posts: 27
Default

In my apps I set the view helper path in the bootstrap.

PHP Code:

$viewRenderer 
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');

$viewRenderer->initView();

//include our custom helpers
$viewRenderer->view->addHelperPath(APPLICATION_DIRECTORY '/views/helpers''My_View_Helper'); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-11-2008, 01:38 AM
Junior Member
 
Join Date: Mar 2008
Posts: 6
Default

Thanks...I think that was exactly what I was looking for
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-20-2008, 12:22 PM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Default Same thing different problem

After adding a

$this->addPrefixPath('Form_Element', 'Form/Element', 'ELEMENT');

in a form constructor my special element is fine but it does not find the standard form elements 'submit'. Putting trace code in the plugin loader it appears that Zend_Loader::isReadable is saying it found a submit.php in my path, but there isn't so it fails to include the path and find the class.

This feels like a php error.

Any Ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-20-2008, 12:40 PM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Default

I tried this

PHP Code:
<?php


    
include_once 'Zend/Loader.php';

    
$path 'Form/Element/';
    
$classFile 'Submit.php';
    if(
Zend_Loader::isReadable($path $classFile)) {
        Echo 
'Yes<hr>';
    } else echo 
'No<hr>';
include_once 
$path $classFile;
and get this

Yes

Warning: include_once(Form/Element/Submit.php) [function.include-once]: failed to open stream: No such file or directory in I:\ws2\chunt\test.php on line 11

Warning: include_once() [function.include]: Failed opening 'Form/Element/Submit.php' for inclusion (include_path=';I:/ws2;I:/ws2/Library') in I:\ws2\chunt\test.php on line 11

That is the cause of my problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-20-2008, 01:17 PM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Angry

Forget my last post, I'm oobviouly stressed by this problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-20-2008, 01:50 PM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Angry

Ok got it but Why?

It seems that Zend is by default in the library path so it finds the real Element class but expectes it to have my prefix.

So do not use a prefix / path that maps to a Zend sub path. i.e I needed to change my Form to FormExtension or something else but not Form.

I do not know why it took me so liong to get this!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:24 AM.