• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HMVC and form_validation.php?

#1
[eluser]Steve Goodwin[/eluser]
Hi All,

I have been trying all day to solve this and it's got to a point where I need to call on the expertise of this forum again since it's probably been covered previously although the search doesn't seem to be dragging anything up apart from another related issue which seems to be flooding the results.

My question is, I have modules and i'm using these in a plug and play way. I.e when i drag and drop a module into my codebase it just works with no trails of code around my codebase that need to be manually added or removed, this is all database controlled.

The problem i've come up against is while trying to keep this modular, when using the form_validation.php file and putting it into the folder structure:

/modules/module-name/config/form_validation.php

It doesn't load, does anyone know how to get around this? I have tried modifying my own My_Form_Validation.php file to no avail.


#2
[eluser]Steve Goodwin[/eluser]
is this forum useless for anything other than how do I get segment 1 of a url?

every question I post gets ignored, this has to be the worst website for posting problems hoping to get any sort of guidance or direction to solving them.

#3
[eluser]PhilTem[/eluser]
Your controllers are all extending the MX_Controller, I guess? Or do they extend the CI_Controller?

#4
[eluser]Steve Goodwin[/eluser]
Phil thanks for your time,

I have an Admin_controller which extends the MX_Controller yes.

All of my other controllers which require the use of the admin controller then extend this.

Is there anything that needs to be done in addition when using this method?

Thanks

Steve

#5
[eluser]LuckyFella73[/eluser]
Do you need your own version of form_validation or would you
like to use the build-in library?

In case the CI form_validation is what you need see this page:
https://bitbucket.org/wiredesignz/codeig.../wiki/Home

You have to scroll down about 3/4 of the page to get to the instructions
how to get the CI form_validation to work propely.

It's described what to do if you want to use the native library in HMVC.
I assume you have wireddesignz HMVC running?

#6
[eluser]PhilTem[/eluser]
According to the HMVC wiki on bitbucket, there is one thing you need to do in order to get form-validation working with HMVC on CI 2.1.x

[quote author="wiredesignz" date="1341183600"]
When using form validation with MX you will need to extend the CI_Form_validation class as shown below, before assigning the current controller as the $CI variable to the form_validation library. This will allow your callback methods to function properly. (This has been discussed on the CI forums also). ie:
Code:
<?php
/** application/libraries/MY_Form_validation **/
class MY_Form_validation extends CI_Form_validation
{
    public $CI;
}

Code:
<?php
class Xyz extends MX_Controller
{
    function __construct()
    {
        parent::__construct();
        
        $this->load->library('form_validation');
        $this->form_validation->CI =& $this;
    }
}
[/quote]

If you already made this change your problem will most likely arise from somewhere else. Then we or I respectively would need some of your code samples (think of using gist if you got many lines of code)

#7
[eluser]Steve Goodwin[/eluser]
thanks for your replies, I have done all of this, I've been using this setup for a while now just trying to improve it.

My code is as follows:

MY_Controller:

Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/* load the MX_Loader class */
require APPPATH."libraries/MX/Controller.php";

class MY_Controller extends MX_Controller
{
    function __construct()
    {
        parent::__construct();

        $this->form_validation->CI =& $this;
    }
}

Admin_Controller:

Code:
class Admin_Controller extends MY_Controller {

public function __construct()
{
  parent::__construct();

        //  Load Libraries
        $this->load->library('ion_auth');

        //  Check if user is logged in?
        if (!$this->ion_auth->logged_in())
        {
            //redirect them to the login page
            redirect('admin/login', 'refresh');
        }
}

}

The my module is structured like this:

- modules
- test
- config
- routes.php
- form_validation.php
- controllers
- test.php
- models
- test_m.php
- views
- add.php
- edit.php
- view.php
- delete.php

My HMVC setup is as follows:

My_Form_validation.php

Code:
class MY_Form_validation extends CI_Form_validation
{
    public $CI;
}

My Config / form_validation.php file setup is:

Code:
$config = array(
    'test/add' => array(
        array(
            'field'   => 'uri',
            'label'   => 'URI',
            'rules'   => 'required|trim|xss_clean|is_unique[uri_tbl.uri]'
        ),
        array(
            'field'   => 'title',
            'label'   => 'Title',
            'rules'   => 'required|trim|xss_clean'
        ),
        array(
            'field'   => 'description',
            'label'   => 'Description',
            'rules'   => 'required|trim|xss_clean'
        )
    ),
    'test/edit' => array(
        array(
            'field'   => 'title',
            'label'   => 'Title',
            'rules'   => 'required|trim|xss_clean'
        ),
        array(
            'field'   => 'description',
            'label'   => 'Description',
            'rules'   => 'required|trim|xss_clean'
        )
    )
);

The function within my controller is as follows:

Code:
public function add()
    {
        // Validate the page
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('add');
        }
        else
        {
            redirect('/test/view');
        }
    }

As you can see everythings setup "as per the guides, topics on the forums and known issues".

I'm posting this because form_validation.php isn't loading at all, the tests i've done are:

- Normal $this->form_validation->set_rules('uri', 'URI', 'required|trim|xss_clean'); and this works.
- I've tested callbacks and they work as well with no trouble.
- When testing the form validation within the form_validation.php file located in /modules/test/config/form_validation.php this fails. I know this isn't loading due to inserting a simple echo "FORM VALIDATION LOADED"; snippet at the top and nothing printing out on the screen.

Any suggestions as to why this feature isn't working? I've read all documentation and instructions before coming to this forum to save basic answers that would point to me being lazy and not reading or googling for existence of this problem currently.

#8
[eluser]PhilTem[/eluser]
We're just trying to narrow down your problem Wink So we start at the very beginning where a lot of problems occur. And advance over time.

However, I still don't know for sure where the problem arises from. Have you tried passing the key for the form-validation to the call of form-validation->run()?

Code:
if ($this->form_validation->run('test/add') == FALSE)

Or, I just came up with a possible solution. Call the key test/test/add. Maybe it must be the module included as well.

Give it a try and report back Wink

#9
[eluser]Steve Goodwin[/eluser]
Thanks phil, yeah I understand, this has just put me majorly behind today thats all, just gonna grab some dinner and will try it out.

#10
[eluser]Steve Goodwin[/eluser]
No joy with that either, I have put together a basic install, if you could help me out i'd be greatful. You can get the download from here:

http://www.weblogics.co.uk/test_hmvc_validation.zip

This includes:

- HMVC
- My_Form_validation requirements for callbacks to work properly.
- Autoloading 'form' and 'form_validation'.
- Admin Controller and My Controller setup as above.
- Test module setup as follows:


- Modules
- Test
- config
- form_validation.php
- controllers
- test.php
- models
- views
- add.php
- edit.php
- view.php
- delete.php

URL once installed should be:

http://hostname/test/add

Hopefully this will highlight any problems which are causing this problem.

Thanks

Steve



Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.