can't access helper file - zend-framework

My helper file Acl.php is in library/Helper and I have included it in bootstrap file as below:-
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initPlugins()
{
$helper= new Helper_Acl();
// $helper->setRoles();
// $helper->setResources();
// $helper->setPrivilages();
// $helper->setAcl();
}
}
but its giving error, Saying -> Fatal error: Class 'Helper_Acl' not found in Bootstrap.php.
Below is my helper file
class Helper_Acl
{
public $acl;
public function __construct()
{
$this->acl = new Zend_Acl();
}
}

in the bootstrap.php , try this , provided your class is in a Helper folder in the library :
protected function _initHelpers() {
Zend_Controller_Action_HelperBroker::addPrefix("Helper_");
}
if it doesnt work tell me , there are other methods.

You need to add Helper_ to your autoloadernamespaces. Typically, this is done in application/configs/application.ini:
autoloadernamespaces[] = "Helper_"

Related

CodeIgniter 3.x.x + WireDesignz HMVC - Call to a member function core_template() on null

I downloaded HMVC files from here and set up my CI 3 installation using these file
Place the MX folder in application/third_party folder
Place the files in application/core MY_Loader & MY_Router
Created a folder module in /application.
Inside module created welcome/controller and welcome/view
In welcome/controller I copied the default welcome controller and in
welcome/view welcome_message.
Then I created a Template Module with and added below code in it
Then I created module for home, here is how my folder structure looks like
class Template extends MY_Controller {
public function __contruct(){
parent:: __contruct();
}
public function core_template($data = null)
{
//$data = new stdClass();
//$data->content = 'home/home_v';
$this->load->view('template/core_template_v', $data);
}
public function dashboard_template($data = '')
{
//$data = new stdClass();
$this->load->view('template/dashboard_template_v', $data);
}
}
Folder Structure
application
modules
template
controllers
Template.php
models
views
core_template_v.php
Home
controllers
Home.php
models
views
home_v.php
Home.php // Controller
class Home extends MY_Controller {
public function __construct(){
parent::__construct();
$this->load->module('Template');
}
public function index()
{
$data = new stdClass();
$data->content = 'home/home_v';
//$this->slice->view('welcome/welcome', $data);
//print_r($data);
$this->template->core_template($data);
}
}
============================================
/* load the MX_Controller class */
require APPPATH."third_party/MX/Controller.php";
class MY_Controller extends MX_Controller {
public function __construct(){
parent::__construct();
$this->load->module('Template');
}
}
I am getting this error:
An uncaught Exception was encountered
Type: Error
Message: Call to a member function core_template() on null
Filename: */modules/home/controllers/Home.php
Line Number: 18
Backtrace:
File: /*/public_html/index.php
Line: 315
Function: require_once
It is working perfectly fine on my local server but when I upload the code to my hosting its throwing this error.

Suitecrm custom template for custom module

I built a custom module using the module builder.
I want to modify templates of my module (edit, detail, subpanel).
How can I tell Suitecrm to use an other template?
Thanks
(Suitecrm 7.7)
it's work for me.
<?php
require_once('include/MVC/View/SugarView.php');
class AccountsViewEdit extends SugarView {
private $smarty;
public function __construct() {
}
public function display() {
$this->smarty = new Sugar_Smarty();
$data = ['a'=> 'a', 'b'=>'b'];
$this->smarty->assign($data);
$this->smarty->display('path/custom/template.tpl');
}
}
You need to create a SugarView in the module and then override the display() method to return the path to your custom template. The convention is keep your templates in a 'tpl' folder in the module.
For example if you look at the 'modules/Accounts/views/view.edit.php' you would just need to add
class AccountsViewEdit extends ViewEdit
{
public function __construct()
{
parent::__construct();
$this->useForSubpanel = true;
$this->useModuleQuickCreateTemplate = true;
}
public function display() {
parent::display(); // TODO: Change the autogenerated stub
return $this->ss->fetch('path/to/your/smarty/template.tpl');
}
}
it's almost the same for the subpanels except the location is in the Dashlets folder. Take a look at modules/Accounts/Dashlets/MyAccountsDashlet/MyAccountsDashlet.php for example.

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.";
}
}

How to access Model in Controller in zend framework?

I am trying to call model methods from controller. but I am getting Fatal error: Class 'GuestModel' not found in. error
following is the code ::
Controller ::
class GuestController extends Zend_Controller_Action
{
public function indexAction(){
$guestbook = new GuestModel();
$this->view->entries = $guestbook->fetchAll();
}
}
Model::
class GuestModel extends Zend_Db_Table_Abstract
{
public function fetchAll()
{
$resultSet = $this->getDbTable()->fetchAll();
$entries = array();
foreach ($resultSet as $row) {
$entry = new Application_Model_Guestbook();
$entry->setId($row->id)
->setEmail($row->email)
->setComment($row->comment)
->setCreated($row->created);
$entries[] = $entry;
}
return $entries;
}
public function getDbTable()
{
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Guestbook');
}
return $this->_dbTable;
}
public function setDbTable($dbTable)
{
if (is_string($dbTable)) {
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
}
Zend Framework autoload depends on using the correct directory structure and file naming conventions to find the classes automagically, from the looks of your code my guess would be you're not following it.
I see 2 possible solutions for your problem:
If possible, rename your class to Application_Model_Guestbook, the file to Guestbook.php and make sure to move it to your application/models/ directory. Then you just need to call it in your controller as $guestbook = new Application_Model_Guestbook();. Check this documentation example;
Create your own additional autoloading rules. Check the official documentation regarding Resource Autoloading.

can't access resource plugin

I have included plugin SecurityCheck.php (Login_Plugin_SecurityCheck) in bootstrap.php. its giving error -> Call to undefined method Zend_Application::getResource() in Bootstrap.php on line 9. Below is my code.
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initPlugins()
{
$bootstrap = $this->getApplication();
$bootstrap->bootstrap('frontcontroller');
$front = $bootstrap->getResource('frontcontroller');
$front->registerPlugin(new Login_Plugin_SecurityCheck());
}
}
How to solve this error.
Try this
protected function _initPlugins() {
$this->bootstrap('frontController')->getResource('frontController')->registerPlugin(new Login_Plugin_SecurityCheck());
}
C of frontcontroller should be captial.