|
In laravel 4 you could also do something like this:php:<? class UserController extends BaseController { public function showProfile($id) { $user = User::findOrFail($id); return View::make('user.profile', array('user' => $user)); } } ?> php:<? App::error(function(Illuminate\Database\Eloquent\ModelNotFoundException $exception, $code) { return Response::view('errors.404', array(), 404); }); ?> If you are looking at Laravel 5 in the future, things are handled differently bigmandan fucked around with this message at 19:35 on May 13, 2015 |
# ¿ May 13, 2015 19:30 |
|
|
# ¿ May 15, 2024 11:23 |
|
revmoo posted:Yes you definitely pointed me in the right direction, thanks. I just finished a 6 week stint of updating legacy (2002!) code, written by an ex-employee, to add a few "emergency" features. Pulling back the layers of mixed logic/presentation cthulhu spaghetti code was... unpleasant. After it was said and done I got the go ahead to do a complete rewrite at least, instead of supporting it for years to come.
|
# ¿ May 14, 2015 22:35 |
|
v1nce posted:... This has burned me before. Keeping stuff separate is a good thing. We've been refactoring a lot of cruft where I'm at and one of the main goals is clean code and maintainability.
|
# ¿ May 19, 2015 15:00 |
|
I've been working on a small problem and I have a solution that works for me, but I'm concerned about style and correctness. The problem appears to be similar to a 0-1 knapsack problem, only I have multiple knapsacks. Is what I came up with decent, or am I a coding horror? edit: After giving it some thought, what I came up with was pretty terrible. I think I came up with a better solution. Maybe. bigmandan fucked around with this message at 21:42 on Sep 3, 2015 |
# ¿ Aug 28, 2015 21:42 |
|
v1nce posted:I'm looking to make Logging easier for my team to use. We're on Symfony2 and passing the logger into everything with DI is a real thorn in everyone's rear end. This may be one of those cases where "breaking the rules" (tight coupling, global state) would be beneficial to you and your team. Logging is one of those things that you need in enough places to warrant this kind of treatment. Definitely go over it with your team though.
|
# ¿ Oct 30, 2015 15:19 |
|
revmoo posted:Awesome thanks. Looks like upgrading won't be too terrible. Beanstalkd should do what you want. The script would push onto the queue and the the daemon would read from it. From what I remember I think pheanstalk is one of the better PHP libs to talk to beanstalkd. It might be a little overkill, but you can scale it out in the future if needed. bigmandan fucked around with this message at 21:02 on Nov 12, 2015 |
# ¿ Nov 12, 2015 20:59 |
|
revmoo posted:Hmm. I'm already using zmq I guess I could just use that. I don't really think I need a "work que" though, as I can process the data in question at once (and can't really scale past that anyway). I'm mainly concerned with "what is the fastest way to send an entire block of data to the daemon and have it picked up by whatever polling mechanism the daemon uses. I can nuke the whole data set with each update, so I'm not sure a message que is really the right tool. If you can nuke the data set with each update then a flat file, like you said, would do it just fine. I assumed the "integrity" of the data being pushed was important.
|
# ¿ Nov 12, 2015 21:21 |
|
joebuddah posted:I have a php form that has a texa area. I want it to take the items in a list and separate each item as its own sql entry. Its not throwing any errors but it is also not sending the database. Can you clarify what you are trying to accomplish? In your example do you want 4 insert queries (one for each "line")? If so: PHP code:
|
# ¿ Feb 11, 2016 20:39 |
|
There Will Be Penalty posted:The thing about prepared statements is you can do this: You are correct of course. Brain fart on my part.
|
# ¿ Feb 16, 2016 16:33 |
|
One thing that can be annoying with Eloquent is that it does not "support" compound keys. I've only ran into this issue a small handful of times, and ended up just writing raw queries for what I needed.
|
# ¿ Feb 16, 2016 23:48 |
|
Since an address only has one type, it would seem more correct to change the method name to be singular as it better represents what is actually happening.
|
# ¿ Mar 11, 2016 23:10 |
|
Gozinbulx posted:I have zero experience with PHP and m here just to shamelessly ask for a ready-made solution. Here's a super low script that does this: https://gist.github.com/dcabanaw/929c0bbf8c5dea56c41f29cba55bccd3 Runs fine with "php -S 127.0.0.1:8080" ( I don't have access to an nginx server atm) - make POSTs to the root to add/update - (key=someKey value=someValue) - make GET requests with http://127.0.0.1:8080?key=someKey Like I said this is super low effort. No error checking, etc... Feel free to do whatever you want with it.
|
# ¿ Apr 14, 2016 21:12 |
|
Experto Crede posted:What is generally considered the best way to write a system that uses modules/plugins? Sound very similar to how Laravels middleware system works. For a naive solution: PHP code:
|
# ¿ Apr 21, 2016 15:08 |
|
rt4 posted:Am I the only one coming to the conclusion that frameworks aren't useful? It seems like Symfony or Laravel expect the programmer to use a whole bunch of code they don't understand to provide features they don't always need. I feel like I can get much better results by pulling together my own libraries for database interactions, routing, authentication, and whatever else. All the frameworks seem to give me is a clumsy installation process and the threat of being forced to migrate away if the framework ever dies. It depends. If you have existing libraries for routing, authentication, etc... that are well tested, use that. If you're working on a team with individuals of varying skill levels, having a framework, it's documentation and large collections of tutorials and videos is really useful. "expecting the programmer to use stuff they don't understand" is a rather silly argument. Of course you're going to want to read the documentation or inspect the source and see how it all works, otherwise you're just going to make things more painful for yourself. If you already have a collection of libraries that work for you, it's probably going to seem like a waste of time learning a framework, but for someone new or someone unsatisfied with what they have, why re-invent the wheel? I'm not sure about Symfony, but I'd hardly call Laravel's setup clumsy now. Maybe in the 3.x and early 4.x versions, but not now.
|
# ¿ Jul 13, 2016 19:22 |
|
v1nce posted:I have felt this way. I do not feel this way anymore. I likely would not dream of rolling my own framework for anything non-trivial providing one exists with a modicum of features that make reasonable sense at first glance. On any language. You explained this much better than I did/could! One thing I noticed when using a framework, is it forced me to write my business logic stuff in such way that it's essentially it's own library. This has worked out well as some of our older projects needed the new code and it was pretty painless to backport it over.
|
# ¿ Jul 14, 2016 15:50 |
|
There are some frameworks that registers a handler for notices and convert them to either errors or exceptions. You can do this your self too with:PHP code:
I find it pretty useful to do so as most php notices should be errors imo.
|
# ¿ Feb 15, 2017 15:26 |
|
HTML Purifier is a decent library for sanitizing input and strips out most XSS content. Ideally you would sanitize the input with HTML Purifier, validate the sanitized input against some rules (valid ranges, format, etc..), and then store it in the database. Escaping output is ideal unless you are doing some sort of HTML based WYSIWYG editor.
|
# ¿ Feb 21, 2017 19:22 |
|
McGlockenshire posted:If you are using your domain's email, use the SMTP server provided by the host of the (MX records for the) domain. PHPMailer is pretty good and my goto for one off scripts, but it's definitely worth learning the API of Swiftmailer if you use any of the frameworks that use it as its core mail lib (Laravel, Yii, etc..)
|
# ¿ Feb 21, 2017 22:56 |
|
If it was not for all the legacy applications and large number of internal libraries we've written, we'd probably switch to C# where I'm at.
|
# ¿ Aug 15, 2017 15:22 |
|
You could check out Laravel Homestead. It is a pretty great development environment even if you are not using Laravel.
|
# ¿ Mar 14, 2018 21:13 |
|
Acidian posted:Alright, thanks guys! Both Sublime and PHP Storm are great. I use PHP Storm most of the time now as I like it's debugger interface a lot better than the xdebug plugin for Sublime. But If I'm just writing something really quick I'll use Sublime still.
|
# ¿ Mar 15, 2018 14:33 |
|
Acidian posted:Wow, that's allot of help, thanks! I will just stick with COUNT() for getting the table size then. You'll be thankful for switching over to PDO. Stick with it, and you'll get there. If you need some general tutorials check out https://laracasts.com/ . While it was initially focused on Laravel, it has expanded out to be a great PHP/webdev resource. There is a lesson for PDO too "https://laracasts.com/series/php-for-beginners/episodes/13"
|
# ¿ Apr 2, 2018 14:51 |
|
96 Port Hub posted:You can pay someone for a certificate or you can use Let's Encrypt for free. I'd recommend LE unless you need something more exotic like a wildcard cert or extended validation. Let's Encrypt can do wildcards now too. https://community.letsencrypt.org/t/acme-v2-and-wildcard-certificate-support-is-live/55579
|
# ¿ Apr 23, 2018 14:47 |
|
itskage posted:Anyone seem to have an issue with PHPUnit dying on a max time limit of 300 seconds? It seem to ignore php.ini settings and any set_time_limit/ini_set features. Our CI is is dying on it when running the full suite on new commits. Running it on just a few tests works fine, so it's like PHPUnit is trying to execute the tests with that time limit for the suite, which isn't going to work for this large project. I'm curious... what do you think it is?
|
# ¿ Jun 4, 2018 17:11 |
|
itskage posted:Someone had a set_time_limit set in a function that iterates over a lot of records. For the purposes of the unit test it doesn't matter, but once set it would stick and PHPUnit would use that for the rest of the test. Changing the time limit in test setup may work, but it could cause issues down the road when other changes are made. To me it would make sense to have the function setting the time limit clean up after itself: PHP code:
Ideally long running tasks should be in some sort of queue system but doing that refactor may be out of scope for your project.
|
# ¿ Jun 4, 2018 19:26 |
|
Cool Matty posted:It's on a socket. I tried TCP for giggles but apparently that's busted in WSL, so they recommend socket anyway. Both nginx and php-fpm are running as my local user (confirmed via top). I was having a similar problem and I eventually got it working in my dev env at home. I'll post my config once I get a chance to do so. edit: Running WSL with Ubuntu 18.04. /home/bigmandan/projects is a symlink to /mnt/c/projects NOT simlinked, but normal file for server config. Had to turn off fastcgi buffering /etc/nginx/sites-enabled/mysite code:
Had to change user/group AND listen.owner and listen.group code:
code:
bigmandan fucked around with this message at 01:21 on Jun 22, 2018 |
# ¿ Jun 21, 2018 13:49 |
|
Acidian posted:So regarding using REST. Is there any common practice to rate limit REST requests in a script? I will set up the larger scripts (that is, scripts that make a lot of calls) to run at like 4 am on Sundays, but even so I worry that making too many requests on the REST API will reduce performance on the Magento server, while the script is running. Also, I might have to run scipts during the day that might not make thousands of requests, but it will still make requests until it's done. I can't really test this impact on performance on my own Magento test environment in a good way. Rate limiting your requests will depend on what the endpoint limits are. Check their documentation to make sure. You could setup some sort of worker queue (beastalkd, rabbitmq, etc...) to perform your requests. The worker would send up to the maximum requests in the allowed time period then "sleep" until the next run. Acidian posted:From what I understand of the REST API, I need to send a PUT or POST request on one object at a time. This means that if I have 500 000 new products, then I need to make 500 000 individual calls on the API. Is there any way of adding more information per request, so that I can maybe send 50 objects in one request? The tutorial or documentation on the Magento site did not seem to indicate that you could. This will really depend on what their endpoint accepts. I've used/written endpoints that accept a json array of objects. You'll have to dig around in their docs and see. Acidian posted:The GuzzleHttp documentation also shows how you can queue up several requests, and then send multiple requests concurrently, but is there any point to that? I would assume it's better to just work through them sequentially. I also don't understand the difference between a synchronous request and an asynchronous request. If you have a lot of requests to make, sending multiple, concurrent, requests at a time could be more efficient than doing each sequentially. Using Guzzle's async would allow you to fire off a bunch of requests then have a handler do something with the response as they complete.
|
# ¿ Jul 9, 2018 15:24 |
|
Most of what you have said seems pretty reasonable. If you want a fairly simple way to handle script(s) from running at the same time, you can use a locking mechanism. For example https://symfony.com/doc/current/components/lock.html If you need finer grain control on when scripts are run you may want to look into supervisord instead of cron.
|
# ¿ Aug 21, 2018 23:35 |
|
Acidian posted:I want to learn to use the Symfony framework, since the application I am using is written in symfony and I want to do some back end modifications later down the line. If what I say sounds reasonable, then I will just stick with that for now, and learn a better way when I start learning Symfony. You can use the lock library without using the rest of the framework.
|
# ¿ Aug 22, 2018 14:28 |
|
Acidian posted:I am running into a weird memory issue with a script. It's a short looping script that uploads an image, so it continously loads in an image file, converts it to base 64 and saves it to a variable, uploads the image to a server and unsets the image file. Then the proccess repeats. Since this is in a while statement, and the variables are the same onces being used over and over, shouldn't the memory allocation (size and address) stay more or less the same with some fluctiuations of 1-2mb depending on the image size? I don't see anything erroneous that would cause memory issues. Without knowing what $ak_client, $mag_client, etc. are doing under the hood it's difficult to tell. You may want to do some profiling with xdebug and cachegrind. Depending on the version I think profiling was removed then added back into xdebug at some point though.
|
# ¿ Sep 5, 2018 16:18 |
|
|
# ¿ May 15, 2024 11:23 |
|
Mr Crucial posted:A newbie question: when should I stop developing frontends in PHP and switch over to something like Vue or React? As mentioned already, Vue is very flexible with how much of the framework you use. You can start with just a few pages at a time and then gradually change into a SPA if you want to. You can also just use components where needed and leave the rest as is.
|
# ¿ Mar 18, 2019 14:20 |