EllisLab text mark
Advanced Search
     
Modular Extensions - HMVC version 5.4 How to prevent direct Module Method access
Posted: 30 July 2012 07:31 PM
Joined: 2012-07-30
2 posts

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:

<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 timeyou should start by reading the <a href="user_guide/">User Guide</a>.</p>
</
div>
<
class="footer">Page rendered in <strong>{elapsed_time}</strongseconds</p>

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

</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:

<?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

 
Posted: 30 July 2012 08:03 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

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 )

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess

 
Posted: 31 July 2012 01:07 AM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2939 posts

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

This method is explained in the Bitbucket wiki.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 31 July 2012 05:00 AM   [ # 3 ]   [ Rating: 0 ]
Joined: 2012-07-30
2 posts

@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:

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:

<?php echo Modules::run ('register_form/register_form/index'); ?> 

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!! grin

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 grin )

Alan

 
Posted: 09 August 2012 10:50 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-07-30
5 posts

Thank you!  This helped me smile

 
Posted: 25 May 2013 06:22 AM   [ # 5 ]   [ Rating: 0 ]
Joined: 2013-05-25
2 posts

you rock. i wanted to secure my widgets, finally got the solution.
Thanks

 
Posted: 20 May 2014 12:11 PM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2011-02-23
21 posts

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.

 Signature 

http://rahendz.web.id—3174DEBB

 
Posted: 20 May 2014 12:22 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2013-07-27
213 posts

@rahendz

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

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

 
Posted: 20 May 2014 02:04 PM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2011-02-23
21 posts
ivantcholakov - 20 May 2014 12:22 PM

@rahendz

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

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

@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

 Signature 

http://rahendz.web.id—3174DEBB

 
Posted: 20 May 2014 02:31 PM   [ # 9 ]   [ Rating: 0 ]
Joined: 2013-07-27
213 posts

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.

 
Posted: 20 May 2014 07:43 PM   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6706 posts

Wiredesignz, will update the HMVC when they release the CI 3.0

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 21 May 2014 02:45 AM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2011-02-23
21 posts
ivantcholakov - 20 May 2014 02:31 PM

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 may implementation of HMVC and to port it alone within your project - I don’t know whether you can do this.

thanks for your reply and support, i’ll try it and come back soon with feedback. thanks again btw.

 Signature 

http://rahendz.web.id—3174DEBB

 
Posted: 21 May 2014 02:47 AM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2011-02-23
21 posts
InsiteFX - 20 May 2014 07:43 PM

Wiredesignz, will update the HMVC when they release the CI 3.0

there is a branch release for codeigniter on github, is that not the official yet? it’s v3.0 right?

 Signature 

http://rahendz.web.id—3174DEBB

 
Posted: 21 May 2014 01:06 PM   [ # 13 ]   [ Rating: 0 ]
Joined: 2013-07-27
213 posts
rahendz - 21 May 2014 02:47 AM
InsiteFX - 20 May 2014 07:43 PM

Wiredesignz, will update the HMVC when they release the CI 3.0

there is a branch release for codeigniter on github, is that not the official yet? it’s v3.0 right?

At this moment narfbg has merged everything from develop branch with release/3.0 branch. I suppose, the release/3.0 branch has been opened for convenience - code is updated there with some delay in comparison to develop branch.

There is no an official release tag however.

I suppose, from your perspective it is more safe to start your project from release/3.0 branch, and to synchronize your code with it not so often. Thus, you will be protected from some accidental and inevitable mistakes (typos mostly) that appear within the develop branch.

@narfbg (if you see this) Do I guess it right?

 
Posted: 21 May 2014 03:12 PM   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6706 posts

He will not update it until it is released to the public.

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 23 May 2014 08:00 PM   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2011-02-23
21 posts

So why @narfbg (if you see this) don’t built HMVC on CI v3? LOL

 Signature 

http://rahendz.web.id—3174DEBB