Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - HMVC version 5.4 How to prevent direct Module Method access
#1

[eluser]Unknown[/eluser]
Hi, I am a Newbie and have been using CI for a while, and have just started with HMVC. I have modified the files etc as in the Modular Extensions 5.4 (Bitbucket) and it works fine.

My question is?

I have just set up 2 modules Module: Base (originally the welcome one) and another Module: Register.

I am experimenting with running the Module register from within the base Module/view file thus:

Code:
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
<p>If you would like to edit this page youll find it located at:</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>

?php echo Modules::run('register/register/index'); ?&gt;

</div>

As I understand it this is a view partial?

Which I can access with the url: http://localhost/CI-HMVC/index.php/ and it loads the base module fine and also the Register Module within it.

Now if I enter http://localhost/CI-HMVC/index.php/register I can also access the Register Module directly on its own, which of course looks bad as it is not loading any of the CSS etc of the base view.

Is there a way to prevent direct access to a Module Method unless it it is called/run from another Module, in this case 'BASE'?

Here is the simple Register Module:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller {

/**
  
  */
public function index()
{
  $this->load->view('register');
}
}

Many thanks, Alan
#2

[eluser]PhilTem[/eluser]
I think what you're looking for is some solution like this (though I cannot confirm this is supported by Modules::run - but I'm guessing it should be Wink )
#3

[eluser]wiredesignz[/eluser]
@spidersbite, Add a _remap() method to your module controller and use it to display an error.

This method is explained in the Bitbucket wiki.
#4

[eluser]Unknown[/eluser]
@PhilTom and @wiredesignz many thanks for the advice, it was early hours in the uk so my brain was a bit fried.

I did try private function _ etc but it didn't appear to solve the issue, I am assuming that Modules::run does not support it.

However just tried @PhilTom's suggestion using _remap() and it appears to work, here is the modified module code:

Code:
function _remap()
{
      echo 'No direct access allowed';
}

public function index()
{
      $this->load->view('register_form');
}

So if I try now to access the module via URL: http://localhost/CI-HMVC/index.php/register_form
I get a warning message 'No direct access allowed'.

But loading the module via the initial Controller/view:
Code:
&lt;?php echo Modules::run ('register_form/register_form/index'); ?&gt;
loads the module correctly.

Even trying to load the module via URL: http://localhost/CI-HMVC/index.php/register_form/index and I still get the warning 'No direct access allowed'.

So in my view _remap() Works a Treat!! :-)

Many thanks again for the advice/info, I know my example was just a very simple one, but I was just getting started with HMVC and modules. (old age :-) )

Alan
#5

[eluser]Lotus[/eluser]
Thank you! This helped me Smile
#6

[eluser]Unknown[/eluser]
you rock. i wanted to secure my widgets, finally got the solution.
Thanks
#7

[eluser]rahendz[/eluser]
first, sorry for my bad english. i just wanna simple ask, i use codeigniter v3.0 and implement the HMVC to it. it works well first when run the welcome module. but when i start using session it return error, i know there is a difference. the old one, session was load using library and in version 3 it load using driver. my question is, when hmvc will support CI 3? or there is something need to be done, to make it works well, some hacks maybe. thanks before.
#8

[eluser]ivantcholakov[/eluser]
@rahendz

https://github.com/ivantcholakov/starter...-edition-3

I did the adaptation some time ago, it is tricky. For saving your time look at my source.
#9

[eluser]rahendz[/eluser]
[quote author="ivantcholakov" date="1400602971"]@rahendz

https://github.com/ivantcholakov/starter...-edition-3

I did the adaptation some time ago, it is tricky. For saving your time look at my source.[/quote]

@ivantcholakov

already try it, even i tried the 4th edition. would you give me some documentation or video how to start new hello word from the begining? i really confused about the directory lol but thanks for replied
#10

[eluser]ivantcholakov[/eluser]
I have no time such things. Here is a hint for version 3:

See platform/application/modules/welcome/views/welcome_message.php

Remove my stuff there and put there echo 'Hello world';

platform/application/modules/welcome/controllers/Welcome.php - remove in the index method my stuff about diagnostics.

And you will have a clean starting page.

Remove the demo directory platform/application/modules/playground/ - you would not need it.
The other modules might be needed at your will.

Remove the directory www/non-mvc/ - it is a demo too.

The HTML layout (the master HTML template) for the pages is within platform/application/views/layouts/site_example.php - you may modify it depending on what css and javascript you intend to use, you may place HTML tags there that is common for all the pages. The Phill Sturgeon's Template library is used for this functionality.

And your knowledge from CI 2.x projects is applicable for this platform too. I tried to keep backward compatibility as much as it is possible. You may try to use your CI 2.x code, libraries etc. with no or very little modifications.

If you pick one of the platforms and you feel some discomfort - open an issue at GitHub on specific things, I will reply.

Edit: The other two options are:

2. You to wait when an official HMVC for CodeIgniter would be released - this I don' know;
3. To analyze my implementation of HMVC and to port it alone within your project - I don't know whether you can do this.




Theme © iAndrew 2016 - Forum software by © MyBB