form validation callbacks are not triggered…
can someone help me to point out the changes needed to fix it??
please?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
January 29, 2011 1:58am
Subscribe [99]#211 / Jan 19, 2012 4:12am
form validation callbacks are not triggered…
can someone help me to point out the changes needed to fix it??
please?
#212 / Jan 19, 2012 4:28am
@psychoder, http://ellislab.com/forums/viewreply/969568/
#213 / Jan 19, 2012 5:20am
@wiredesignz, thanks a lot… 😊
#214 / Jan 25, 2012 4:48pm
@psychoder, http://ellislab.com/forums/viewreply/969568/
@wiredesignz With the new version of the framework 2.1.0, the quoted solution does not work any more since access to
$this->form_validation->CIhas been set to protected.
To have callback working again, you will need to extend CI_Form_validation and do something like the following:
class MY_Form_validation extends CI_Form_validation {
public function set_ci_reference(MX_Controller $ci)
{
$this->CI = $ci;
}
}Then within your MY_Controller
class MY_Controller extends MX_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->form_validation->set_ci_reference($this);
}
}Thanks for all the hard work.
#215 / Jan 25, 2012 4:59pm
@ericrjones1, I suggest you look at the linked solution more carefully. There is a MY_Form_validation extension shown with a public $CI class variable.
#216 / Jan 25, 2012 5:11pm
:red: Fail.
You are right. I didn’t notice that you had set the visibility to public.
#217 / Jan 26, 2012 9:27am
@wiredesignz: Being the smug developer that I am, I followed your solution provided with one exception. I used the following:
$this->form_validation->CI = $this;Based upon my PHP version information, I would have assumed that $this would be passed by reference since $this is referring to my controller ( an object - in PHP 5 all objects are passed by reference automatically, right? ).
$ php -v
PHP 5.3.8 (cli) (built: Sep 28 2011 17:34:36)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick RethansHowever, when using the form_validation_helper function validation_errors the conditional statement on line 1054 says that the $CI->form_validation object isn’t set even though the $CI->load->is_loaded(‘form_validation’) returns ‘form_validation’;
Dumping the $CI object, I can see the following loaded classes, but no form_validation object.
protected '_ci_classes' => &
array
'session' => string 'session' (length=7)
'encrypt' => string 'encrypt' (length=7)
'form_validation' => string 'form_validation' (length=15)So the gist is:
// Doesn't work ( mine )
$this->form_validation->CI = $this;
// Works ( yours )
$this->form_validation->CI =& $this;I feel like I am totally missing something. If you can, will you please explain to me why my code doesn’t work.
Thanks for all your help.
#218 / Jan 27, 2012 6:56am
It won’t be passed by reference as long as you use = since = is an assign-operator nothing more.
= doesn’t create a pointer but creates a copy. Other than get_instance() does, since this returns a static variable (have a look at the code).
So you really need to do
$this->form_valdiation->CI =& $this;to assign it by reference rather than pass by reference (pass by reference basically only works for functions, not assignments 😉 )
The & is the reference symbol.
#219 / Feb 03, 2012 2:53pm
Hi WireDesignz,
I was wondering if you know why the following code is returning “GO” on the main controller, but returns “FAIL” for each module loaded via modules::run inside the views?
third_party/MX/Loader.php
class MX_Controller
{
public $autoload = array();
public function __construct()
{
$class = str_replace(CI::$APP->config->item('controller_suffix'), '', get_class($this));
log_message('debug', $class." MX_Controller Initialized");
Modules::$registry[strtolower($class)] = $this;
/* copy a loader instance and initialize */
$this->load = clone load_class('Loader');
$this->load->_init($this);
/* autoload module items */
$this->load->_autoloader($this->autoload);
$this->data = new stdClass;
// Global information
$this->data->assets_url = base_url('assets');
$this->data->title = '';
$this->data->db = @unserialize($this->session->userdata('db'));
if(!empty($this->data->db))
{
$db_connection = $this->load->database($this->data->db);
if($db_connection)
{
echo 'GO';
}
else
{
echo 'FAIL';
}
}
}
public function __get($class) {
return CI::$APP->$class;
}
}Thanks! 😊
#220 / Feb 07, 2012 5:35am
I was trying to make a module for db backup using dbutil.
When in MX controller
$db1 = $this->load->database($db_group,TRUE);
$this->db = $db1;
$this->load->dbutil();
$backup =& $this->dbutil->backup();the backup contains the first loaded db, while when in a normal CI Controller it correctly gives backup for the selected group
When I do $this->load->dbutil() in mysql_utility.php in dbutil() $CI =& get_instance(); gives me the db which was autoloaded (from autoload)
Any ideas?
#221 / Feb 07, 2012 12:14pm
@osci, Try this:
$db1 = $this->load->database($db_group, TRUE);
$this->load->dbutil();
$this->dbutil->db =& $db1;
$backup =& $this->dbutil->backup();#222 / Feb 07, 2012 2:03pm
This correctly sets the db to the desired one. Thx for the tip.
I also tried
$db1 = $this->load->database($db_group)which should set the app db to the one loaded
if ($return === TRUE) return DB($params, $active_record);
CI::$APP->db = DB($params, $active_record);
return CI::$APP->db;but it returned wrong db again. Is this program related to DB class or MX Loader?
#223 / Feb 07, 2012 2:40pm
Once a database group is loaded it cannot be changed to another group by calling $this->load->database($db_group) again. This is part of the CI logic in the database loader method.
if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
{
return FALSE;
}MX_Loader merely duplicates this method but uses the $CI super object differently when assigning the $db class variable to it.
#224 / Feb 11, 2012 3:59pm
Hi wiredesignz,
Is it correct that loading modules in views does not work if modules controllers contain the same file / class name?
I have the following routes active and are the reason why controllers share the same name in each module:
$route['(\w{2})/cms/([a-zA-Z_-]+)/(:any)'] = '$2/back_end/$3';
$route['(\w{2})/cms/([a-zA-Z_-]+)'] = '$2/back_end/index';
$route['(\w{2})/cms'] = 'back_end';File structure application/modules:
/slider/controllers/slider.php
/slider/controllers/back_end.php
/products/controllers/products.php
/products/controllers/back_end.php
Now this will fail (returns nothing):
<?php echo modules::run('slider/back_end/somemethod'); ?>If I move the method to the unique named slider controller and try:
<?php echo modules::run('slider/slider/somemethod'); ?>or
<?php echo modules::run('slider/somemethod'); ?>It works fine. Do you know how to solve this?
Thanks!
#225 / Feb 21, 2012 8:09am
hey wiredesignz,
i kind of bumped into a problem, i am using MX in building a kind of economic application, but i want to be able to let other programmers to develop other modules(plugins) to extend the core modules.
for example: i have the “clients” module that has 3 tabs with informations, and with a module(plugin) i want to add a 4th tab (jquery tabs) how can i do that?
in theory i have the core functionality and view, and i have to somehow extend them to add another tab and functionality for that tab.
<div id="tabs">
<ul>
<li><a href="#tabs-1"><?php echo lang('client_general_info');?></a></li>
<li><a href="#tabs-2"><?php echo lang('client_bank_info');?></a></li>
<li><a href="#tabs-3"><?php echo lang('client_contact_person_info');?></a></li>
</ul>
<div id="tabs-1">
<fieldset>
<section>
<label class="title"><?php echo lang('client_general_info');?></label>
</section>
<section>
<label for="cif"><?php echo lang('client_cif_label');?></label>
<div>
<?php echo form_input(array('name'=>'cif', 'id'=>'text_placeholder', 'title'=> 'ex: RO17068477', 'value'=>'', 'required' => 'required', 'placeholder'=>'ex: RO17068477')); ?>
</div>
</section>
</fieldset>
</div>
<div id="tabs-2">
<fieldset>
<section class="b">
<label class="title"><?php echo lang('client_bank_info');?></label>
</section>
<section>
</fieldset>
</div>
<div id="tabs-3">
<fieldset>
<section class="cp">
<label class="title"><?php echo lang('client_contact_person_info');?></label>
</section>
</fieldset>
</div>
</div>here is a sample of my view file.