Note that there are some explanatory texts on larger screens.

plurals
  1. POI'm trying to extend the CodeIgniter Form Validation library
    primarykey
    data
    text
    <p>This is my custom validation function. It uses geocoding from <a href="http://in-the-attic.com/2010/08/02/codeigniter-google-maps-library-using-google-maps-api-version-3/" rel="nofollow noreferrer">a Google Maps CodeIgniter library</a> to check if a location exists.</p> <pre><code>public function address_check($str) { $this-&gt;load-&gt;library('GMap'); $this-&gt;gmap-&gt;GoogleMapAPI(); // this method checks the cache and returns the cached response if available $geocodes = $this-&gt;gmap-&gt;getGeoCode("{$str}, United States"); $this-&gt;form_validation-&gt;set_message('address_check', 'The %s field contains an invalid address'); if (empty($geocodes)) { return FALSE; } else { return TRUE; } } </code></pre> <p>If I place the function above inside my Controller along with the following rule, it works perfectly well.</p> <pre><code>$this-&gt;load-&gt;library('form_validation'); $this-&gt;form_validation-&gt;set_rules('location', 'Location', 'callback_address_check'); </code></pre> <hr> <p>Now I simply want to move it out of my Controller. So I'm trying to extend my CodeIgniter Form Validation library as per this <a href="https://stackoverflow.com/a/10652934/594235">SO answer</a> and <a href="http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html" rel="nofollow noreferrer">the CI documentation</a>.</p> <p>I created a file here: <code>/codeigniter/application/libraries/MY_Form_validation.php</code>:</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Form_validation extends CI_Form_validation { public function __construct() { parent::__construct(); } public function address_check($str) { $this-&gt;load-&gt;library('GMap'); $this-&gt;gmap-&gt;GoogleMapAPI(); // this method checks the cache and returns the cached response if available $geocodes = $this-&gt;gmap-&gt;getGeoCode("{$str}, United States"); $this-&gt;form_validation-&gt;set_message('address_check', 'The %s field contains an invalid address'); if (empty($geocodes)) { return FALSE; } else { return TRUE; } } } </code></pre> <p>And from within my controller, I am setting the rule like this...</p> <pre><code>$this-&gt;load-&gt;library('form_validation'); $this-&gt;form_validation-&gt;set_rules('location', 'Location', 'address_check'); </code></pre> <p>The first problem I found and solved myself was that nothing was happening because <a href="https://stackoverflow.com/a/10652934/594235">that SO answer</a> incorrectly specified the file name to be <code>My_Form_validation.php</code> where it should have been <code>MY_Form_validation.php</code></p> <p>Now that the function is being called, the new problem is that I am getting the following error:</p> <blockquote> <p>Message: Undefined property: MY_Form_validation::$load</p> <p>Filename: libraries/MY_Form_validation.php</p> <p>Line Number: 12</p> </blockquote> <p>This is line 12:</p> <pre><code>$this-&gt;load-&gt;library('GMap'); </code></pre> <p>I can't access a library from within a library? What's the proper way to fix this? I'd prefer not to auto-load the GMap library since I won't be using it all the time. Any other problems within my method?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload