Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    codemonkeynorth
    @codemonkeynorth
    Use that to route to your controller method and then i guess just return a json encoded response
    echo json_encode(array("blablabla"=>$variable));
    }
    // \MyApp::route()->get()->where( 'ajax', 'my-custom-ajax-action' )->handle( 'ExampleController@ajax' );
    @ajax wont be specifically required, its just the name of a method in controller
    Atanas Angelov
    @atanas-dev
    The example in the docs is pretty much all you need - you specify the ajax action and who it should apply to (authed vs unauthed users) then you return whatever you want to respond with (return MyApp::json( $my_data ) will automatically encode $my_data as a JSON response)
    codemonkeynorth
    @codemonkeynorth
    MyApp::json is what I was looking for thanks. Did not see it in the docs when I skimmed over
    2pi.pl
    @piotrk_twitter
    @atanas-dev What are the chances of releasing any time soon the add/blade-component-support@wpemerge-blade branch?
    Or is there any alternative to this great Blade feature?
    Atanas Angelov
    @atanas-dev
    Unfortunately it's going to be awhile before I can get to it.
    Romain
    @Romaixn
    Thanks for your replies ! I did the controller, but how can I call my ajax in JS ? Is the name of the action is 'my-custom-ajax-action' ? (for example if I use \MyApp::route()->get()->where( 'ajax', 'my-custom-ajax-action' )->handle( 'ExampleController@ajax' );)
    Romain
    @Romaixn
    My Controller always return me '0'
    codemonkeynorth
    @codemonkeynorth
    Set your params for authed/non-authed users
    // Match requests from any user:
    \App::route()->get()->where( 'ajax', 'my-ajax-action', true, true )->handle( $handler );
    What’s your js?
    Romain
    @Romaixn
    Yes I have that..
    My JS is simple :
    data = {
                'action': 'see-more-ajax-action',
                'query': loadmore_params.posts,
                'page': loadmore_params.current_page
            };
    
            $.ajax({
                url: loadmore_params.ajaxurl,
                type: "POST",
                data: data,
    I have a 200 status code but returned '0' in success function
    codemonkeynorth
    @codemonkeynorth
    what does loadmore_params.ajaxurl equate to?
    oh you're doing a POST... but your route is get().. either use route()->post()->.. or route()->any()->...
    Romain
    @Romaixn
    ooooh... my bad of course
    Indeed it's work, thanks a lot for that
    codemonkeynorth
    @codemonkeynorth
    @Romaixn no worries . I learned something. Whaf is your ajaxurl tho? Is it just pointing to wp-admin/admin-ajax.php ?
    Piotr
    @piotrku

    The situation is like this:
    I pass all front-end requests through WPEmerge - MyApp::route()->all() so when I invoke some regular page, a view wp-content\themes\my-theme\views\page.php is automatically displayed.

    I'm wondering how to achieve this:
    I like this route -> controller -> view schema, but I don't want to create routes for all standard WP URLs .
    I'd like to have some controller(s) in the middle to inject some data (variables) when needed to some of the standard-route-views.
    How can I create a controller that would be automatically invoked for those standard WP routes before (in this case the page.php) view is served?
    Should I use middleware for that? One method that would check what route is this and delegate handling of this request to some dedicated classes?

    Atanas Angelov
    @atanas-dev

    If you want to inject some data into a view regardless of how it is rendered you can use View Composers which do just that: https://docs.wpemerge.com/#/framework/views/view-composers

    There's an article on the subject that you may find useful as well - it uses outdated syntax but the concepts are the same: https://wpemerge.com/2019/01/24/view-composers-passing-data-and-staying-dry/

    Alexander
    @xenx-efy
    Hello. I noticed that if I register an image import '@images/progress.svg', it goes to the fonts folder, not the images. How can this be corrected? Or maybe I'm doing something wrong?
    Alexander
    @xenx-efy
    And also puts it in the "Images" folder, but in this form: export default __webpack_public_path__ + "fonts/mountains.59dff4a121.svg";
    codemonkeynorth
    @codemonkeynorth
    Is it breaking anything?
    Alexander
    @xenx-efy
    yes, I cannot get svg images from images folder
    it is a little not logical
    codemonkeynorth
    @codemonkeynorth
    I mean doesn’t the path resolve in your code so it just pulls it from your fonts folder and shows up anyway?
    or are you getting a 404
    Alexander
    @xenx-efy
    I'm using this construction App::core()->assets()->getAssetUrl('images/progress.svg') for getting images
    and it returns path which isn't get image
    image.png
    file content looks like this ^
    codemonkeynorth
    @codemonkeynorth
    Have you edited your webpack config at all?
    Oh also check your svg have the correct header. I had trouble on a server with it not recognising them because the xml definition was missing
    Alexander
    @xenx-efy

    Have you edited your webpack config at all?

    no

    codemonkeynorth
    @codemonkeynorth
    Has this been stripped off the top off the SVG. I’m not saying it’s the issue but....
    <?xml version="1.0" encoding="UTF-8"?>
    Alexander
    @xenx-efy

    <?xml version="1.0" encoding="UTF-8"?>

    this did not help, it seems that the problem is in the configuration of the webpack.

    codemonkeynorth
    @codemonkeynorth
    are you saying the svg file actually has that error in the svg file?
    Alexander
    @xenx-efy
    this error happend because webpack put in file content instead svg tag this command export default __webpack_public_path__ + "fonts/progress.c5bcc87d11.svg";
    maybe I don't need to import images in index.js file?
    but it works with png and jpeg extensions
    codemonkeynorth
    @codemonkeynorth
    Can’t work out why it’s putting it in fonts
    Alexander
    @xenx-efy
    me too, welcome to the club)
    codemonkeynorth
    @codemonkeynorth
    I don’t see anything in the webpack config that would do that
    Alexander
    @xenx-efy
    how do it works in your case?
    maybe I really once changed config depends on it
    codemonkeynorth
    @codemonkeynorth
    I’ve never had an issue with it. However... the image you are using in your PHP code. Did you import it somewhere in the js?