hmvc in codeigniter cannot access modules - php

Iam trying to switch to hmvc in codeigniter. I will explain my issue from scratch itself. First I downloaded Codeignter 3.0 version from http://www.codeigniter.com/download and when I check my browser it is showing the welcome message of CI. Now to add hmvc structure I downloaded the hmvc modular extension from https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads. And placed the core and third party modules inside my CI folder. Then I created a Folder inside the application folder and named it as modules. Within modules I created a folder say test. I have a controller folder which contain test.php.
class Test extends MY_Controller {
public function index()
{
echo "hey my first module is ready";
}
}
But when i call the module in the url like localhost/index.php/test i got a page not found error. Am i missing any configuration? I got all other controller working well before i switched to hmvc. How can i fix this. Thanks in advance.

Do you forget this piece of code in your config file?
$config['modules_locations'] = array(
APPPATH.'modules/' => '../modules/',
);
Do you created your own Controller? Cause you extends MY_Controller.
If not, extend CI_Controller or MX_Controller
For more information read the documentation at wiredesignz's HMVC for Codeigniter
Kind regards

Try to follow this tutorial.Here you will get ready to use HMVC folder. http://www.darwinbiler.com/ready-to-use-codeigniter-modular-extensions-hmvc/

Related

CakePHP not recognizing Twig Layouts

I'm new to CakePHP and I need to integrate Twig for a project. First I installed the TwigView plugin (https://github.com/predominant/TwigView) and tried to follow the small set of instructions.
Installation
Plugin sources
I cloned the plugin repository in /app/Plugin/. A folder TwigView is created.
Twig sources
I placed Twig sources under /app/Plugin/TwigView/Vendor/ in a folder named Twig
Configuration
I added this to my /app/Config/bootstrap.php
CakePlugin::loadAll();
and this to AppController
public $viewClass = 'TwigView.Twig';
I also granted write privileges to everybody in /app/Plugin/TwigView/tmp/views
Problem 1
The application keeps asking for .ctp files, and I need to use my .tpl templates. I tried adding this in AppController
public $layout = 'default.tpl';
But it will complain, saying that it can't find default.tpl.ctp
Problem 2
How can I pass parameters to the twig templates from Cake controllers?

CodeIgniter Modular Extensions & the i18n library

I have been using the CodeIgniter i18n library by Jérôme Jaglale (http://maestric.com/en/doc/php/codeigniter_i18n), which works great for my project.
But since I need to write separate modules, I recently added CodeIgniter Modular Extensions ( https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc ) and the navigation breaks.
How can I solve this issue please, I would love to use both the i18n library & Modular Extensions.
I think my application navigation fails to work because i18n library introduces adds a language segment in the site url, in my case my url is localhost/index.php/en/home and after adding Modular Extensions, my navigation/links stop working.
Thank you in advance.
Recently, I try to use HMVC with i18n and have similar problem. Below is my solution.
1.first you need to go to here HMVC select "Branches" to download HMVC extension, don't download the one on github it might not work.
2.Unzip HMVC extension inside the folder copy two files "MY_Loader.php" and "MY_Router.php" from core folder to Codeigniter's "application/core" after that copy "MX" folder from "third_party" to Codeigniter's "application/third_party". By this point your HMVC is installed, however it will not work because i18n cause the problem so if you run your website it might not display.
3.You need to get new version of i18n which support both HMVC and none HMVC, the old version of i18n seems not support HMVC. Go to here i18n download it and take time to read the description on github.
4.Before this step I suggest you to backup "application/core/MY_Config.php" and "application/core/MY_Lang.php" in case something goes wrong you can reverst back. Unzip i18n inside folder copy file "language.php" from config folder to Codeigniter's "application/config", copy two files "MY_Config.php" and "MY_Lang.php" from core folder to Codeigniter's "application/core", finally copy "MY_language_helper.php" from helpers folder to Codeigniter's "application/helpers". So far you have new i18n installed, but you need to configure it to make it work, otherwise you might get error message.
5.Open "application/core/MY_Config.php" and replace the line require_once APPPATH . "libraries/MX/Config.php"; to require_once APPPATH . "third_party/MX/Config.php"; then open "application/core/MY_Lang.php" replace the line require APPPATH . "libraries/MX/Lang.php"; to require APPPATH . "third_party/MX/Lang.php";. Why? because it point to the wrong directory, the MX folder is located in "third_party" not "libraries" in case you don't know, if you don't change it you might get error message.
6.To add new language(Not create language file) you need to open "application/config/language.php". You see at top the code block with comment says "Supported Languages" there already have English and Russian language configure for you just need to copy the template and change to the language you want, it's very easy. Be aware folder's name must exactly the same as folder in "application/language".
7.According to i18n github description you need to add these line
$route['^(en|de|fr|nl)/(.+)$'] = "$2";
$route['^(en|de|fr|nl)$'] = $route['default_controller'];
to the "application/config/routes.php". Be aware this line $route['^(en|de|fr|nl)/(.+)$'] = "$2"; in old i18n probably is $route['^(en|de|fr|nl)/(.+)$'] = "$1"; the difference is "$1" have to change to "$2", otherwise you will got problem.
8.To create language file is same as the method you did in old i18n. Now test your website with multi-language to make sure everything work fine.
9.Create your module. How? Create a folder name "modules" inside Codeigniter's application folder, inside modules folder you can start to create your module. That's say you want to create a module call foo, you just need to create a folder name it "foo" and then inside foo folder you can create three folders controllers, models and views. Create a php file with name foo with the code below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Foo extends MX_Controller
{
public function index()
{
echo "<h1>class foo this is module test</h1>";
}
}
Enter url to run your module, if you see "class foo this is module test" then it work.
Remember module class must extends from MX_Controller.
If you still encounter any problem just ask.

CakePHP TwigView Plugin Missing View Error

I am using CakePHP 2.4.2 and this plugin by predominant.
I want to use TwigView with CakePHP and found that the plugin above is compatible with CakePHP 2.0. Followed all the installation steps, however, getting the Missing View error while executing the script.
My AppController.php
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $viewClass = 'TwigView.Twig';
}
The view's extention is .tpl, however, even after adding the Plugin it is still looking for .ctp extention.
I have also loaded the plugin in bootstrap.php using
CakePlugin::load('TwigView');
define('TWIG_VIEW_CACHE', APP . 'tmp');
Any Idea what could go wrong.
http://api.cakephp.org/2.4/source-class-Controller.html#209-214
Set the Controller::$ext property in your app controller to "tpl" and your're done.
Searching before asking is also always a good idea, see CakePHP View change extension

Loading a Facebook plugin and config application for CakePHP

I am new to CakePHP, but I've started using CakePHP 2.0. Unfortunately my host has PHP 5.2.6 and CakePHP 2 won't run. I want to add a Facebook plugin to my CakePHP 1.3 application. I downloaded the plugin into the app\plugins\facebook folder and copied facebook.php from app\plugins\facebook\config\facebook.php to app\config\facebook.php
class AppController extends AppController {
var $helpers = array('Facebook.Facebook');
}
It is reporting missing facebook helper app\views\helpers\facebook.php
<?php CakePlugin::load('Facebook'); ?> //in bootstrap.php is giving an error
Is there anything I would have done in bootstrap.php to cause this and how might I fix it?
All you need to do Enable the plugin in app/Config/bootstrap.php , You also need to add your appID and AppSecret.
For Details you can see the configuration in following link
https://github.com/Pollenizer/CakePHP-Facebook-Plugin
Hope it works for you.

HMVC and Views in folders (Codeigniter)

I am using Tank Auth library in Codeigniter with HMVC and the entire tank auth mvc files are in its own module called 'auth'. tank auth loads a view (domain.com/application/modules/auth/views/auth/login_form.php) found inside a folder (auth) using:
$this->load->view('auth/login_form', $data);
As far as I know the above code will load login_form.php inside the auth folder properly without HMVC. However with HMVC, I need the following code to get the view to load:
$this->load->view('auth/auth/login_form', $data);
Is there a setting that we should change so we dont have to refer to the view file by (module name)/(views folder name)/(view filename) ? Or is this perfectly normal and most people does it this way?
It seems troublesome that I have to add the module folder name 'auth' to every view() function call, and change all of them should I change the name of the module folder.
Assuming you're using Modular Extensions - HMVC:
If you have auth set up as a module already, you can just call:
$this->load->view('login_form', $data);
The file /views/login_form.php will be loaded from within the current module. This applies to models, language files, libraries etc. Think of the module as its own application, this is what you would normally do.
Additionally, to load a file from another module or a controller outside the module's directory, you can use $this->load->view('auth/login_form');
If the file is not found, it will check the other module paths including the default directory. This may or may not be the way other HMVC packages work, I'm not sure - but it's the way MX works.

Categories