Jump to content

maxxd

Gurus
  • Posts

    1,657
  • Joined

  • Last visited

  • Days Won

    51

Posts posted by maxxd

  1. It sounds like you want to sort by geographical distance when searching address but by post ID when other fields are searched? If so there are a couple options - either you're doing the WP_Query call manually (the global $gmw_query variable makes me think this is the case) at which point check the search parameters and update the ORDER BY clause there. Or, this is hooked into a generic WP query at which point you'll want to use the posts_orderby hook to see if the post in question is a search and modify the ORDER BY clause appropriately.

  2. Hey y'all.

    I'm currently working on a project at work and it involves creating a package with assets. Laravel's ServiceProvider has the loadRoutesFrom() and loadViewsFrom() methods which are all well and good, but the only solution I can find in the documentation or code for syncing javascript, font, and style files from the package to the full Laravel install is to run the artisan publish command. This means I'd have to run the publish command every time I make a change which is clearly not a solution I'm excited about.

    My solution at the moment is to use a symlink from the compiled assets location in the package directory to the appropriate directories in the public webroot of the overriding install - all good and working except for one thing. When I use the mix() helper in my view to load the javascript files they can't be found [ie: <script src="{{ mix('packagename/js/main.js') }}"</script>] where packagename is the symlink; however, when I point directly to them it works perfectly [ie: <script src="packagename/js/mix.js"></script>]. The asset() helper function works just fine.

    My only concern with just linking directly is that now I can't use versioning in my mix build process, my tester has a computer that caches aggressively.

    TL;DR - has anyone come across a situation where Laravel's native mix() function can't traverse a symlink or is this something known in the php ecosystem that I've somehow never come across before?

  3. No, backslash is an escape character. Note how every character after a backslash is red in your screencap - that means it's being interpreted as a command character (tbh I'm not sure that's the right term - it's being interpreted as something other than a simple character in a string). So where you have `\`, you should have `\\` - this will escape the second backslash and make the interpreter read it as a character in a string. So, basically

    "C:\Program Files\your\path\php.exe"

    becomes

    "C:\\Program Files\\your\\path\\php.exe"

     

  4. Doing my digging and it appears this is chapter 4. Code from the sample:

    <?php
    Require_once("e10dog.php");
    $lab = new Dog;
    // ------------------------------Set Properties--------------------------
    $dog_error_message = $lab->set_dog_name('Fred');
    print $dog_error_message == TRUE ? 'Name update successful<br/>' : 'Name update not successful<br/>';

    Note the lack of 'bool' before $dog_error_message. I'm not trying to be a jackass here, but when you're learning a language you have to read the tutorials completely, follow them accurately, and listen to the people who know what they're talking about when they try to help with any confusion.

    • Great Answer 1
  5. lab.php does not define a class. It uses a class - these are two very different things. Look at my previous examples and the use of the word 'class'. Then compare that to your own files; I think you'll see the important difference.

    I don't have Learn PHP 8 from apress, but the source is available through github. What chapter is this lesson?

  6. Right. And I see where you instantiate an instance of that class in the global namespace, right before you try to type a variable in that same global namespace. The code you're showing isn't inside a class or a method/function signature. For instance,

    <?php 
    class Testing{
    	private bool $truefalse;
    }

    is perfectly valid, because it's inside a class.

    <?php
    function testing(bool $truefalse){
    	echo $truefalse;
    }

    is also perfectly valid as that's typing a function parameter. However,

    <?php
    bool $truefalse = false;

    is not valid, as it's not within a class or function.

  7. All that having been said, understand that any time span type calculation is ... just harder than it should be. You look at it and it's like "oh, yeah - no problem". Then you start actually working on it and it's far more complicated than you might think. So even the idea of comparing not only start time and end time as implied above, you suddenly then have to consider potentially time zones and then daylight savings time (which is it's own barrel of fish)...

  8. Where you assign $day_end_each, you've got several (frankly, redundant) calls to date() to define the month, day, and year. Replace those calls with specified values and you can set any date you'd like.

    However, I have a sneaking suspicion that the problem may lie with the direction of your comparison. It seems like your query is working when considered from the start of the shift, but there's no consideration for the end of the shift. So perhaps there needs to be a condition that looks at $row['shift_'.$i.'_end'] or $row['shift_'.$i.'_start'] + $shift_duration (or something similar)?

  9. I would start off by using var_export to dump the result of each of your conditionals.

    echo "<pre>".var_export(date("Y-m-d", strtotime($row["shift_" . $i . "_start"])) == date("Y-m-d", strtotime($date_each)), true)."</pre>";
    echo "<pre>".var_export(date("Y-m-d H:i:s", strtotime($row["shift_" . $i . "_start"])) <= $day_end_each, true)."</pre>";
    echo "<pre>".var_export($row["member_shift_" . $i . "_on_call"] == 0, true)."</pre>";

    From there you can check if and where your logic chain is failing, and that'll give you a more specific place to start actually debugging.

  10. To clarify, it's standard practice to omit the closing tag in files that only include PHP. If you're mixing your PHP into HTML (which is it's own kettle of fish) you can either close the PHP block before you write your HTML or - as ginerjm mentioned - you can use a heredoc and then output the markup from that variable.

  11. This is typically called a toast notification. For instance, if you happen to use Laravel you'd install toastr as a dependency in pacakge.json:

        "dependencies": {
            "toastr": "^2.1.4"
        }

    Create a toast component or partial:

    <script>
    	@if(Session::has('message'))
    		window.toastr.success("{{ session('message') }}");
    	@endif
    	@if(Session::has('error'))
    		window.toastr.error("{{ session('error') }}");
    	@endif
    	@if(Session::has('info'))
    		toastr.info("{{ session('info') }}");
    	@endif
    	@if(Session::has('warning'))
    		window.toastr.warning("{{ session('warning') }}");
    	@endif
    </script>

    Include that component/partial in your main template file:

    		@include('components.toast')

    Finally, set the message in $_SESSION like so:

    return Response::redirect('/dashboard')->with('message', 'Data Saved!');

    Obviously if you're not using Laravel you'll have to do some digging but hopefully that's a decent starting point.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.