Rendering Custom View in SuiteCRM not working - sugarcrm

I have a controller that calls my custom view, but the custom view is not getting rendered.
I cant understand the issue, everything looks correct to me.
Neither is it displaying any errors or warnings.
My module name is SCRV_SSRS_CRM_Reports_View
I have below code in:
custom/modules/SCRV_SSRS_CRM_Reports_View/controller.php
require_once('include/MVC/Controller/SugarController.php');
class SCRV_SSRS_CRM_Reports_ViewController extends SugarController
{
function action_test(){
$GLOBALS['log']->fatal('Am in Controller');
$this->view = "test";
}
}
And in
custom/modules/SCRV_SSRS_CRM_Reports_View/views/view.test.php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.list.php');
class SCRV_SSRS_CRM_Reports_ViewViewtest extends ViewList
{
public function display()
{
echo "HIIII";
$GLOBALS['log']->fatal('Am in View');
}
}
Cant see the view getting rendered when I access it by
http://localhost:8080/dev-crm/index.php?module=SCRV_SSRS_CRM_Reports_View&action=test
I cant see HIIII displayed on screen or the log entry.

Controller should be
class CustomMeetingsController extends SugarController {
$this->view = 'invite';
}
and View should be like
class CustomMeetingsViewinvite extends ViewList {
public function display() {
echo 'hiiiii';
}
}

Related

I can't pass parameters to the component Wire Elements Modal

I can't pass parameters to the component.
I have 3 files:
Inside Livewire/test.blade.php
...............
onclick='Livewire.emit("openModal", "test-modal", {{ json_encode(["id_code" => $client->id_code]) }})'>
Inside /Http/Livewire/TestModal.php
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
public function render($id_code)
{
dd($id_code);
return view('livewire.test-modal');
}
}
And livewire.test-modal which displays the content of the modal window.
But I can't get the id_code.
Let's see if someone can help me with this. Thanks.
So I had the same issue pretty much.
I solved it by adding the $id_code to the mount method. I hope it helps
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
public function mount($id_code){
$this->id_code = $id_code
}
public function render()
{
$elCliente = Client::where("erp_code", $this->id_code)->first();
dd($elCliente);
return view('livewire.test-modal');
}
}
Livewire.emit("openModal") will emit an event that you can listen to in your components. The render() method in Livewire does not accept a parameter, so instead you need to listen to that event, and do your actions in a separate method instead.
By adding
protected $listeners = ['openModal' => 'openModal'];
the component will now listen to the event openModal (key in the array) being dispatched, and then fire the method openModal() (value in the array). Since you pass in two parameters, "test-modal" and a JSON parameter, you can accept those in that method.
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
protected $listeners = ['openModal' => 'openModal'];
public function openModal($name, $data)
{
$this->id_code = $data['id_code'];
}
public function render()
{
return view('livewire.test-modal');
}
}

Trying to disable layout in zend

I try to disable layout in zend action in this way:
$this->_helper->layout->disableLayout();
But it doesn't work:
Fatal error: Call to undefined method Application_Controller_Helper_Layout::disableLayout() in application/controllers/AssetController.php on line 18
I reckon that its, because I made my own helper.
Bootsrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initMyActionHelpers()
{
$this->bootstrap('frontController');
$layout = Zend_Controller_Action_HelperBroker::getStaticHelper('Layout');
Zend_Controller_Action_HelperBroker::addHelper($layout);
}
}
application.ini
resources.frontController.actionhelperpaths.Application_Controller_Helper = APPLICATION_PATH "/controllers/helpers"
and my helper
class Application_Controller_Helper_Layout extends Zend_Controller_Action_Helper_Abstract
{
public function preDispatch()
{
}
}
Thanks!
If you want to rewrite Zend default layout helper, please extend Zend_Layout_Controller_Action_Helper_Layout.
class Application_Controller_Helper_Layout extends Zend_Layout_Controller_Action_Helper_Layout
Then you will still be able to use default disableLayout() function if you are not overwriting it in your own helper.
Try testing it using:
class Application_Controller_Helper_Layout extends Zend_Layout_Controller_Action_Helper_Layout
{
public function preDispatch(){}
public function disableLayout(){
echo "I won't disable layout anymore, because I overwrote the action with displaying this string.";
}
}

Assigning Values to Views when using $this->renderScript

in order to avoid copy/paste, i can use a unique view for different actions, i can do this using one of these ways
$this->renderScript('index/index.phtml');
$this->view->var = "hello world";
or
$this->_helper->viewRenderer('index');
$this->view->var = "hello world";
if i want to use a different controller i have to use the 1st one, the viewRenderer is ok, but when i use the renderScript it shows nothing like var is not defined. how can i assign values to the view script?
index.phtml would be somthing like this
echo $this->var ;
It should work the way you described it
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
$this->view->var = 'echo me in any action viewscript and i will show you text';
}
public function indexAction()
{
// action body
$this->view->test = 'Don\'t put me here becuase this is not the action that is run';
}
public function testAction()
{
// action body
$this->view->test = 'Hello world';
$this->renderScript('index/index.phtml');
// or $this->_helper->viewRenderer('index');
}
}
in my view (index.phtml)
i have
<?php echo $this->test;?>
When i go to /index/test/ it will show "hello world"...
Also when i do it in another controller it gives me the result
class MyController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
$this->view->test = 'Hello world';
$this->renderScript('index/index.phtml');
}
}

Zend frame work Custom view helper error

Hi am trying to add custom helper throughout my application
Have done following steps
index.php
$view = new Zend_View();
$view->addHelperPath('My/View/Helper', 'My_View_Helper');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
Helper class in My/View/Helper
class My_View_Helper_Common extends Zend_View_Helper_Abstract
{
public function example()
{
return "ok";
}
}
now calling in view index.phtml
$this->example()
am getting this error
Uncaught exception 'Zend_View_Exception' with message 'script 'error/error.phtml' not found in path (.\application\views\scripts\)' in C:\xampp\htdocs\wyfixture\library\Zend\View\Abstract.php:924
Stack trace:
#0 C:\xampp\htdocs\wyfixture\library\Zend\View\Abstract.php(827): Zend_View_Abstract->_script('error/error.pht...')
#1 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action\Helper\ViewRenderer.php(903): Zend_View_Abstract->render('error/error.pht...')
#2 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action\Helper\ViewRenderer.php(924): Zend_Controller_Action_Helper_ViewRenderer->renderScript('error/error.pht...', NULL)
#3 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action\Helper\ViewRenderer.php(963): Zend_Controller_Action_Helper_ViewRenderer->render()
#4 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action\HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#5 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action.php(523):
please help me
In addition to Vikas answer.
To call more than one method in a view helper you can use code like this:
In My/View/Helper/Example.php
class My_View_Helper_Example extends Zend_View_Helper_Abstract
{
public function example()
{
return $this;
}
public function foo()
{
return 'foo';
}
public function bar()
{
return 'bar';
}
public function __toString()
{
return $this->foo();
}
}
In you views:
echo $this->example()->foo() // prints foo
echo $this->example()->bar() // prints bar
echo $this->example() // prints foo
Seems like you have two problems here:
Your 'application/views/scripts/error/error.phtml' is missing. You can restore it and you'll get more accurate exception message at once.
Your helper class should contain a method named after the helper.
So, in your case it's file My/View/Helper/Example.php with the following body
class My_View_Helper_Example extends Zend_View_Helper_Abstract {
public function example() {...}
}
Then you'll be able to call it from the view with
$this->example()

how to have two controller actions, one shared view for Zend_Controller_Action Class?

How do you specify a custom view script for a given Controller Action method?
For example:
Class UserGalleryController extends Zend_Controller_Action
{
public function fooAction()
{
$this->view->actionMsg = 'foo';
// (uses foo.phtml automagically)
}
public function barAction()
{
$this->view->actionMsg = 'bar';
//use foo's view script ?????
}
}
I basically want to have one view script (foo.phtml)
Thanks :-)
public function barAction()
{
$this->view->actionMsg = 'bar';
$this->render('foo');
}