how to add custom action in sugarcrm? - sugarcrm

So i have a custom module MLB what i want is add a custom action in detailsview.php for a button to send Messages, i already have the action but i have no idea how i put it !!

You can override \custom\modules\{modules_name}\views\view.details.php display function like this:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.detail.php');
class modules_name extends ViewDetail {
function modules_nameViewDetail(){
parent::ViewDetail();
}
function display(){
// include your custom function code here
parent::display();
}
}
?>

Related

$this->view->layout()->setContentKey('') problem!

i set a new contentkey for showing menu in right column of my site.like this:
public function menuAction()
{
$this->view->layout()->setContentKey('menu');
}
this is layout code:
<div class="center_col"><?php echo $this->layout()->content; ?></div>
<div class="right_col"><?php echo $this->layout()->menu; ?></div>
but there is a prob!! after setting menu contentKey every action result showing in right column (content don`t work!)
i have a plugin for menu action , i think it is that reasone!
this is my plugin:
class Places_Controller_Plugin_ActionSetup extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup( Zend_Controller_Request_Abstract $request)
{
$front = Zend_Controller_Front::getInstance();
if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) {
$actionStack = new Zend_Controller_Plugin_ActionStack();
$front->registerPlugin($actionStack, 97);
} else {
$actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack');
}
$menuAction = clone($request);
$menuAction->setActionName('menu')->setControllerName('index');
$actionStack->pushStack($menuAction);
}}
i nead menu action call in all pages , so i use of this plugin!
is there any way for solve my prob?!
answer with Marcin and SMka help :
public function menuAction()
{
$this->view->placeholder("menu")
->append($this->view->render("menu/menu.phtml" ));
}
in your Menu action just do render to named segment
// Renders my/login.phtml to the 'form' segment of the
// response object
$this->render('login', 'form');
no need layout()->setContentKey, this method is for other things

Way to define others layout() parts such layout()->content?

Ive done some search but no success.. i am trying to figure out how to define others layout() parts such layout()->content variable.. i would love to get int layout()->navigation (a custom one) which display the navigation..
Any ideas ?
Thanks.
Not sure if this is what you want, but you can create additional 'parts' of layout simply by assigning a value to your new part. ZF will take care of the rest. For example, in a bootstrap.php you could do:
public function _initNewLayoutPart() {
$view = $this->bootstrap('view')->getResource('view');
$view->layout()->newpart = 'some new part';
}
Then in your layout.phtml you could just echo the new part:
<?php echo $this->layout()->newpart; ?>
It is possible by just creating a new variable in layout, you can define it in your controller (preferably in init or postDispatch). Just like this:
public function init()
{
$this->view->layout()->motd = '<b>Message of the day.</b>';
}
Then in your actual view where you want to see the message, all you have to do is:
<?php echo $this->layout()->motd; ?>
If you want something fancier, such as rendering a whole page or sidebar, try the following:
public function init()
{
$this->view->layout()->sidebar = $this->view->action('render', 'sidebar');
}
With render being the action (including render.phtml) and sidebar being the controller.

Load Zend_Form from a view helper in Zend?

Is it possible to load a Zend_Form from a view helper? I'm using thise form in a login action method. But I also want this form to be visible on the navigation on every page (so without the login action actually being called yet), the post method of the form will send to the login action method.
I'm guessing it should be done with a view helper but I don't see how.
Any ideas?
I tried with this:
my view helper:
class Zend_View_Helper_LoginForm
{
function getLoginForm(){
$form = new Form_LoginForm();
return $form;
}
}
and I call it from my layout like this:
<?php echo $this->form(); ?> but this doesn't work. (I'm able to call the same form through an action method though!)
In this case it gives me this error (which doesn't make sense because my helper is only 9 lines long):
Warning: Missing argument 1 for Zend_View_Helper_Form::form() in C:\xampplite\htdocs\zendpr\library\Zend\View\Helper\Form.php on line 44
Your view helper should extends the Zend_View_Helper_Abstract class and the method of the view helper must have the same name as the class :
class Zend_View_Helper_LoginForm extends Zend_View_Helper_Abstract
{
function loginForm() {
$form = new Form_LoginForm();
return $form;
}
}
and you call it like this in your view script :
echo $this->loginForm();
If you call :
echo $this->form();
You are using the view helper Zend_View_Helper_Form
Have your View_Helper extend Zend_View_Helper_Abstract and override the setView()
class Zend_View_Helper_XX extends Zend_View_Helper_Abstract {
public $view;
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
}
Initialise the form in your controller action and set the form reference
// controller action code
$this->view->form = $form;
Then in the view helper you can reference the form via the view
// view helper code
$this->view->form;
class Zend_View_Helper_LoginForm extents Zend_Form {
function getLoginForm(){
$form = new Form_LoginForm();
return $form;
}
}
OR
$this->view->form=$form;
Both are going to return the form. The view form is more specific for view.
Add this into your phtml view file
echo $this->form();
To answer this question - Remove the Parenthetical
Should be
echo $this->form;

Do an ZendX autocomplete in a layout

I would like to use ZendX_Jquery autocomplete in a partial, which is in my layout.
How can I do that :
My layout :
<div class="prefix_11 grid_5" id="header_search_engine">
<?php echo $this->partial("/common/_search_engine.phtml"); ?>
</div>
An action :
public function autocompleteAction($search='') {
$this->view->autocompleteElement = new ZendX_JQuery_Form_Element_AutoComplete('ac');
$this->view->autocompleteElement->setJQueryParam('source', '/searchengine/getsearch');
$this->view->autocompleteElement->setJQueryParam('minLength',
$this->configApplication->autocomplete->max_cars);
}
How can I use it in the partial, in the layout ?
How can i send the autocompleteElement in the partial view ?,
Thanks to help.
Fabrice
#fabrice
I had the same problem using autocomplete with my layout and I have solved it with the following:
Use placeholder for my searchBox
Create a Zend_Controller_Plugin that extends Zend_Controller_Plugin_Abstract
in predispatch execute method renderUiWidgetElement of autocomplete element.
set the placeholder with the form
Example:
class myLibrary_Controller_Plugin_SearchBox extends Zend_Controller_Plugin_Abstract
{
public function preDispatch()
{
$this->searchBox();
}
public function searchBox()
{
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->initView();
$view = $viewRenderer->view;
$searchForm = new Application_Form_JQueryForm();
$searchForm->acProduct->renderUiWidgetElement();
$view->placeholder('searchBox')->set($searchForm);
}
}
The key is to launch method renderUiWidgetElement();. Without it, the layout will not add the neccesary javascript to the autocomplete element. I got this information from here: http://cientouno.be/blog/categorie/zend-framework
Thanks a lot to cientouno!
Thank you, but, I used the ActionStack for display on every page. And do, I use a form.
public function autocompleteAction() {
$formAutoComplete = new Frontoffice_Form_Autocomplete();
$this->view->autocompleteElement = $formAutoComplete;
$this->_helper->viewRenderer->setResponseSegment('autocomplete');
}
and, in the layout :
<div class="prefix_10 grid_6" id="header_search_engine">
<?php echo $this->partial("/common/_search_engine.phtml");
echo $this->layout()->autocomplete;
?>
</div>
You can send the autocompleteElement in the partial view with this code.
<div class="prefix_11 grid_5" id="header_search_engine">
<?php echo $this->partial("/common/_search_engine.phtml", array('autocompleteElement ' => $this->autocompleteElement); ?>
</div>

How do i assign a custom helper to each view differently in zend framework

i have a custom helper written which returns the html form as string which extends the Zend_view-hepler_Abstract
Now i have 3 helpers .How do i assign each helper to a different view .
It is something like this in the controller
class abc extends Zend_controller_front{
public action page1Action (){
// I want to use a different Helper
//How do i assign custom1 helper to this view Separately
}
public action page2Action (){
// I want to use a different Helper
//How do i assign custom2 helper to this view Separately
}
public action page3Action (){
// I want to use a different Helper
//How do i assign custom3 helper to this view Separately
}
}
um, should you be inheriting from Zend_Controller_Action not Zend_Controller_Front?
also the word 'action' is not a valid php keyword?
just use the view helper in your view script, so in abc/page1.phtml
print $this->page1Helper()
similarly for page2 and page3
but there may be an easier way... you can just
print $this->form;
and the form will print without the need for a helper?