hmvc load controller Cannot redeclare class CI - codeigniter-3

i developed an CMS in codeigniter 2 with HMVC and now im trying to migrate to Codeigniter 3. I have the follow issue.
This works in view codeigniter 2
<?PHP $configuracion = $this->load->controller('configuracion/todos');
?>
I recive the error: Fatal error: Cannot redeclare class CI in /home/xxxx/public_html/application/third_party/MX/Base.php on line 57
This is the controller:
<?php
class Configuracion extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->model('configuracion_m', 'Configuracion_m');
}
function todos() {
return $this->Configuracion_m->get_all();
}
Thanx!!!!!

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.

Cakephp multiple forms in single view

On my edit view I have created 2 forms :
<?php echo $this->Form->create('EditPasswordUserForm')); ?>
<?php echo $this->Form->create('EditInfoUserForm')); ?>
Hence, I created 2 Models (2 files) :
class EditPasswordUserForm extends User
{
and
class EditInfoUserForm extends User
{
Controller User :
public function edit($slug)
{
$this->loadModel('EditPasswordUserForm');
$this->loadModel('EditInfoUserForm');
$editpassword = $this->EditPasswordUserForm->findBySlug($slug);
$editinfo = $this->EditInfoUserForm->findBySlug($slug);
if(empty($this->data))
{
$this->request->data['EditPasswordUserForm'] = $editpassword['EditPasswordUserForm'];
$this->request->data['EditInfoUserForm'] = $editinfo['EditInfoUserForm'];
}
}//end edit
I got this error message :
Erreur: Class 'User' not found
Fichier: C:\xampp\htdocs\projectmvc\app\Model\EditPasswordUserForm.php
Could you please help me.
Thank you
Ligne: 4
You just import User model in your extend models, like as
App::import('Model', 'User');
class EditPasswordUserForm extends User
{
//
}
and
App::import('Model', 'User');
class EditInfoUserForm extends User
{
//
}
For best documentation read Behavior for Model Inheritance
You don't need to create two classes.
You can just do:
echo $this->Form->create('User', array('action' => 'editPw'));
echo $this->Form->create('User', array('action' => 'editInfo'));
In your UsersController:
class UsersController extends AppController {
public function editPw() {...}
public function editInfo() {...}
}

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

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.

can't access helper file

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_"