This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

gfactor
gfactor

Hello everyone, Am trying to build a 3 select field chained dropdown plugin with reusable components. I simply do not know where this error is coming from.

Here is my controller:

<?php namespace Misc\Csc\Components;

use Backend\Classes\Controller; class Csc extends ComponentBase { public function construct() { parent::construct();

}
public function getIndex()
{
    $input = Input::get('option');
    $country = Country::find($input);
    $state = $country->state();
    return $state->get('id','state');
}
public function getCity()
{    
    $cityinput = Input::get(‘stateoption’);
    $state = State::find($cityinput);
    $city = $state->city();
    return $city->get('id','city');
}

}

Route: Route::get('csc/dropdowncs','Misc\Csc\Controllers\Csc@getIndex()');

Error: The component 'Misc\Csc\Components\Csc' does not contain a method 'getAfterFilters'.

Last updated

axomat
axomat

I do not recognise the error and I have seen a lot of errors :-) but you are using a very unusual approach to writing components. You do not specify the component details for example. It is also unusual to override the october routes. Whilst you are permitted to do this (I have done it myself) you need to know what you are doing. I would guess that if you created the component in a standard october way then the error would go away. Sorry if that is not helpful...

gfactor
gfactor

I got the country list from the DB into the Country select field. And am using JQuery script onChange to call for the state & city as well. Here is my component:

class Csc extends ComponentBase {

public function componentDetails()
{
    return [
        'name'        => 'CSC dropdown',
        'description' => 'Country, State &amp; City JQuery dropdown'
    ];
}
public function onRun()
{
    $this->page['countries'] = $this->countries = CscCountry::getCountryList(); 
}

public function getIndex()
{
    $input = Input::get('option');
    $country = Country::find($input);
    $state = $country->state();
    return $state->get('id','state');
}
public function getCity()
{    
    $cityinput = Input::get(‘stateoption’);
    $state = State::find($cityinput);
    $city = $state->city();
    return $city->get('id','city');
}   

}

And here is the HTM file:

    <script type="text/javascript">     
    jQuery(document).ready(function($){
$('#country').change(function(){
        $.get("{{ url('csc/dropdowncs')}}", 
            { option: $(this).val() }, 
            function(data) {
                var state = $('#state');
                state.empty(); 
                $.each(data, function(index, element) {
                    state.append("<option value='"+ element.id +"'>" + element.state + "</option>");
                });
            });
    });

$('#state').change(function(){
        $.get("{{ url('csc/dropdowncity')}}", 
            { option: $(this).val() }, 
            function(data) {
                var city = $('#city');
                city.empty(); 
                $.each(data, function(index, element) {
                    city.append("<option value='"+ element.id +"'>" + element.city + "</option>");
                });
            });
    });
}); 
</script>
axomat
axomat

It is difficult to tell but it seems like you are routing to Csc in the Controllers directory but Csc is in Components. I am not sure if you are new to October, sorry if not, but Components and Controllers are both controllers, the first is for the front end, the second is for the backend. Mixing up the two is unusual.

gfactor
gfactor

Yeah, am new to October, however, i also understand that the component is for the frondend. The reason i tried controller was because the component didn't work either.

This is the error when i routed to the component "The component 'Misc\Csc\Components\Csc' does not contain a method 'getAfterFilters'.

gfactor
gfactor

I also tried re writing my route to this: Route::get('csc/dropdowncs', [function() { Misc\Csc\Components\Csc::getIndex(); }]);

Then i get this error:

"Non-static method Misc\Csc\Components\Csc::getIndex() should not be called statically, assuming $this from incompatible context" on line 4 of C:\wamp\www\webname\plugins\misc\csc\Routes.php"

axomat
axomat

If you are new to this then honestly, forget changing the routes, just create a simple component that generates a list of countries, then use the ajax framework built in to October to get the states.

g25598967895
g25598967895

I had the same problem, I've solved it by changing the "use Backend\Classes\Controller" for "use CMS\Classes\Controller", and my class extends Controller.

1-8 of 8

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.