HMVC Unable to load the requested file - codeigniter-2

Hello i have some problem, i use Codeigniter Modular Extensions - HMVC.
Problem is when i try to show my module.
An Error Was Encountered
Unable to load the requested file: quicklinks_show.php
I have two modules
1.Dashboard
2.Quicklinks
The problem arises when I try to call and show another module in dashboard module.
I put this code in Dashboard/view/dashboard_view.php module
<div id="modules">
<?php modules::run('quicklinks/show');?>
</div>
In my Quicklinks modules i have simple Show() function
public function show(){
$this->load->view('quicklinks_show');
}

Make sure you have the view folder is named correct, so controller*s*, model*s* and view*s*

Try this pull request:
https://github.com/EllisLab/CodeIgniter/pull/1818
I tested that and it looks like this is the best hmvc solution.
Download here: https://github.com/dchill42/CodeIgniter/tree/hmvc_unit

It may be too late to reply but you may get the answer in this in-depth article of HMVC.

Related

Codeigniter 4 - controllers won't work unless I add them directly to Routes.php

Can anyone tell me:
Do I have to declare all of my controllers in Routes.php in Codeigniter 4?
I can't seem to get a controller to work unless I add it directly to the "Routes.php"
I have created my controllers properly and the Home controller is working after install and setup.
If I add the controller My_page.php :
<?php
namespace App\Controllers;
class My_page extends BaseController{
public function index(){
echo "Controller 'My_page' -> function index() ";
}
}
?>
I get a
: "404 - File Not Found
Sorry! Cannot seem to find the page you were looking for."
If I now add the controller to the rout - i.e.:
$routes->post('my_page', 'My_page::index');
Then my controller works properly and I get the "Controller 'My_page' -> function index() " when I visit www.mydomain.com/my_page
I have also tested:
www.mydomain.com/index.php/my_page
and this makes no difference.
I am using the .htaccess that comes with the download. I have updated the base URL to www.mydomain.com/
The documentation is confusing to me - https://www.codeigniter.com/user_guide/incoming/routing.html#setting-routing-rules ;
it sounds like they are saying have to declare all classes with routes?
Why are my controllers not working without declaring them specifically in Routes.php?
And am I misunderstanding 'setAutoRoute(true)' it also does not seem to work - I expect that I can turn this on and simply create my controllers pretty much like in CI3?
If you don't enable auto-routing you most certainly need to add all routes which you are allowing, anything else will fail with error 404. As #parttimeturtle mentioned - autoroute it is disabled by default since 4.2.
So in short - Yes, you need to add all controllers, their functions and the appropriate http methods. (That includes CLI routes as well)
You can use $route->add(), which will allow all http methods, it's however more secure to explicitly set them with their methods.

Dompdf Laravel Test

I am having problems resolving this issue. I want the user to be able to download a report when pressing the button. I keep on getting Action not defined, and if I change my route it will simply not load the app.
Any help would be appreciated.
/************View***************/
<button>Download PDF</button>
/*************Controller****************/
public function pdf($id){
$report=Report::findorFail($id);
$pdf = PDF::loadView('reports.show', compact('report'));
return $pdf->download('server_report.pdf');
}
You need to have your action defined in a route.
For example:
Route::get('pdf','ReportController#pdf');
Also, make sure that if ReportController has a resource route then the pdf route goes above it.

smarty not working in codeigniter

I installed Smarty in Codeigniter and it's not really working. Here is what I did:
I followed this instructions:
http://sunwebexpert.com/books/detail/PHP/integrating-smarty-and-codeigniter.html
But I also put another file in the library: parser.php which is a library to do parsing (I've used it before with smarty and worked well)
the on Codeigniter's autoload.php wrote this:
$autoload['libraries'] = array('parser','smarty');
On main controller I wrote this function to test:
public function index()
{
$this->data['d'] = 2;
$this->parser->parse('base/test.tpl', $this->data);
}
but the result is no error display and I see the variable 'd' as it is wrote in the template:
{$d}
So I have two questions:
Why can't I see the variable value if I installed smarty as I did before in other projects?
How can I enable to see errors if there are?
The problem is that in codeigniter, there is a built-in library called Parser. That's why this may cause conflict with your library name. Try to rename your library name or use built-in library.
Here is how to display error on codeigniter.
Hope it will be useful for you.

google calendar with codeigniter

I'm trying to integrate Google Calendar in my php application (I use CodeIgniter for this).
I have a problem with my controller calendar.php.
<?php
session_start();
Class Calendar extends Controller {
function Calendar(){
echo 'start';
parent::Controller();
echo 'okkkkkkkk';
require_once '/home/me/framework/ZendGdata/library/Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
}
but there is a problem with parent::Controller() because 'okkkkkk' is not printed.
Could anyone help me please?
Change
parent::Controller();
to
parent::__construct();
parent::Controller() doesn't work in CI because as of CI 2.1.2, the constructors are declared using PHP's __construct() method.
As a sidenote, it seems you are using an older version of CI. CI 2.o onwards, the base controller class is called CI_Controller as opposed to just Controller. You should look into updating your project by replacing the system folder.
You can find the full working code in this following link https://github.com/omerkamcili/ci_google_calendar_api.
After down loading the code create your service account, OAuth client Id's in the following link http://console.developers.google.com.
Then replace the client_id,client_secret,redirect_uri's in your project file in the following path -> /project_folder/application/config/client_secret_846685841138-t0a5b9d2i655e7km54md8j440jcg5rr5.apps.googleusercontent.com.json file
Finally download and replace the google-api-php-client in the following file path /project_folder/application/third_party/google-api-php-client

Setting up Codeigniter HMVC with tank auth

I am having trouble getting a working Codeigniter version 2.0.3 with hmvc and tank auth(set up as a module) setup properly. I have installed CI properlly and then install HMVC with these directions https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
I get to my welcome controller/view as example just fine which means the HMVC is working. Next I try to add tank auth to the project by adding it to a folder in the modules folder. It has the proper controller/view/model etc.. setup within the tank auth. I even added in routes something like
$route["auth"]="auth/login";
I also extended the controller within the auth module to MX_Controller like as directed. Also in the constructor I have :
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('security'); <--failing to load this
$this->load->library('tank_auth');
$this->lang->load('tank_auth');
$this->form_validation->CI =& $this;
It seems to be redirecting fine to the module however it comes up with an error saying ::
An Error Was Encountered
Unable to load the requested class: security
What am I doing wrong? Does any one have a working CI installation with HMVC and tank auth as a module so I can see how its done? I'm new to HMVC, thanks
I found the same problem, but i solved by simple adding a comment to the
$this->load->library('security');
so it will look like this:
//$this->load->library('security');
since security its now part of the codeigniter core, i guess its already loaded by default, and everything seems to be working pretty good
it is in Helper now according to CodeIgniter 3.0 user guide
try:
$this->load->helper('security');
I fix this, by creating Security.php file in application/libraries directory with the following code:
require_once(BASEPATH.'core/Security.php');
class Security extends CI_Security { }
I found a solution, I simply took the security.php file from codeigniters system/core folder and dropped it into system/libraries.
move the file security.php from system/core to system/libraries
then edit core/codeigniter.php line number 204 from $SEC =& load_class('Security', 'core'); to $SEC =& load_class('Security', 'libraries');
Security.php is present in "codeigniter/system/core/Security.php"
so provide this path your problem gets solved easily
load->library('../core/security');
I Read CodeIgniter 3.X User Guide and I was found that "Security" is available as a 'helper' Now.
So you need to change this;
$this->load->library('security');
into
$this->load->helper('security');
XSS Filtering
The Input class has the ability to filter input automatically to prevent cross-site scripting attacks. If you want the filter to run automatically every time it encounters POST or COOKIE data you can enable it by opening your application/config/config.php file and setting this:
$config['global_xss_filtering'] = TRUE;
You need to read a CodeIgniter 3.0 User Guide there are so many changes and implementation or please Refer change log.

Resources