I'm beginner at Lumen (and php) and I am a bit confused all the structure as the only people I talked about Lumen to were interns just like me. I created a project where I use Models where all my methods and functions are, I have constructor in my controller class where I call functions from class Model.php and then pass that to view.blade.php (in resources folder) where all my html goes. I return view from controller. My question, is that correct? Should I have class for view? If my structure is not correct, how should it look? What correct sequence of passing information should be then?
Thank you in advance for claryfing it for me :)
I know MVC structure should be similar to .NET but still I am confused somehow.
You should not use Lumen for a fully-fledged application with HTML views, assets, etcetera.
Lumen is a microframework specifically designed to build APIs in a lightweight environment, which allows you to focus entirely on the resources to serve, instead of the design.
Lumen is way faster compared to Laravel, for example the Routing is handled by FastRoute instead of Illuminate Routing, which is quicker and lighter for the application.
Use Laravel for what you are trying to do.
Related
I have an existing website running on PHP, MySQL CSS, JS and Ajax.
For future projects, I would like to use the Laravel framework to create new pages or functionality to the existing website... let's say a blog, for instance.
Is this possible?
Is the Laravel framework compatible with an existing website that is not set up using the MVC framework?
The reason is that I would like to make my work easier and more efficient and the use of a framework would be helpful.
Please let me know if you need any other info, I know the question is a little broad.
Thanks,
Justin
yes it's possible but of course maybe with difficulties.
you should put your web files in /views directory, convert your php files to controllers or library files and put your assets in /public directory.
then you can assign routes to your controller and call it form outside of the application.
main job is put your code into controller or libraries. is it possible to split your code into separate logical units? and extract model logic (as php mvc says) from your main code.
so if you have a clean code with good design and minimum dependencies you can think more about it. this could be a good challenge if you go through it cautiously. be careful to not fail and waste your time.
I've made an online store in php for school, and now my teacher wants this project to have a Laravel Framework. And I have no freaking idea how to do it. Are there any possibilities to implement this framework to my project, or my project to this framework, without starting from scratch? If yes, how should I do it?
irrespective, its going to involve a lot of rework. A lot also comes to down to HOW you've developed your original php app. Laravel is a Model View Controller framework. For starters all your routes (http redirects) are generally managed in a single file (web.php). Your views can be traditional php, however, Laravel gives you a good templating engine called Blade which allows you to shorthand code and keep code a lot cleaner. Models control your table relationships, controllers handle the functions/code/crud etc.
You will love how easy it is in most respects - especially the way eloquent data queries work etc. It can greatly reduce your code.
If your teacher wants you to LEARN Laravel specifically, I would say YES you will be starting over - however, your logic in the code should just need reworking rather than start from scratch.
There are heaps of posts around HOW to install Laravel (apache, virtual box, homestead etc) - once your ready, its super simple to create a new project and start building away... If you are new to MVC, you should do some tutorials first (e.g. laracasts or other).
Best of luck :)
I've recently started work at a new company, and was initially assigned to help the web development team.
To my horror, their template application they use to set up every single one of the projects they do, is completely procedural.
I am very eager to swap it over to OOP, but before I do that I need to actually understand how to create a project.
The initial work is there - there's an index.php that swallows all calls made to the site/web application.
What I need is a tutorial on how to set up proper routing so that I can look at a URL and go "call this function in this controller" instead of including a bunch of PHP files to get the job done.
Could someone please point me in the right direction?
I was in the same situation and this course helps me a lot to learn more about MVC and Routing in PHP. As #Armin said you can use Slim Framework or phroute .In the other hand, you can use Laravel framework to take care not only routing but also all the other challenges as a PHP developer you might have in the future
It sounds like they don't use any well known framework. They probably also don't want to use one. I think the best solution in this case would be some routing library. You could use the Slim Framework. You will understand everything you need to understand in about 30 minutes. It's very easy to setup and easy to extend.
You should not try to write your own routing library, it'll become quickly a quite complex thing. You will just reinvent the wheel and loose time.
I also would recommend the Slim Framework. I've spent way too much time trying to roll my own framework with routing but the maintenance and updating on my own framework got it the way of actual projects.
Slim is extremely easy to understand and offers a lot of flexibility to mold your own type of application. Between the routing, middleware, containers, and using the Eloquent DB ORM it has plenty to offer.
As others mentioned before, don't reinvent the wheel. There are plenty of tools out there you can lean on that allows you to focus on the actual project.
I think that Create your own PHP Framework from Symfony documentation is the thing you are looking for. You shouldn't be worried about the title, it's not only about creating frameworks. It shows you how to start using Symfony components in plain PHP application and eventually create your own framework.
But creating framework part is not the most important one. Understanding how to use object-oriented components in your code is the key part.
Of course, one of the components is routing. It's use is described in first chapters: Introduction, The HttpFoundation Component, The Front Controller, The Routing Component, Templating (don't skip this one!). But I recommend continuing to the end, it's easy to read and very interesting article. Even if you don't want to use Symfony (or it's components) this article will help you understand how to use any modern PHP components.
I am making a controller for each type of request post/put/get.
So my question now is, what is the best way to put controllers in subfolders when using L 4.2 ?
/controllers/subfolders..
I've seen some people using namespacing and some people simply makes a subfolder and put their controllers in it then run composer dump autoload-
But is there any "best practice" way to do it in L 4.2?
I do it the namespace way. One advantage this gives is that we can have same named classes inside the folders. Currently in a Laravel 4.2 app that I'm building, I am using controllers/api subfolder, with the namespace of Api for all the classes in it. And one of the classes is UsersController. Which might also be used for the frontend website, so now you will have to say FrontendUsersController, or something weird and long. So to avoid this, better get in shape with namespaced controllers.
Also, Laravel 5 advocates namespacing for your project, so does PSR standard. So this is probably much better way in the long run.
I have an project that is used by many users and it's written in Codeigniter. I'm very happy with my application but I'm getting lost with Codeigniter because of the functionality of the framework and my application is getting too big for Codeigniter (that is what I think).
I want to go from Codeigniter to Zend, but the application is too big to begin all over again because there is still more functionality to come.
I don't know if someone has experienced or tried it, but does anybody know if it is possible to integrate Codeigniter into Zend as an module and migrate in steps to the Zend Framework 2?
Sorry for my bad english by the way :-)
Having experience with small and medium-scale projects with both CodeIgniter (CI) and Zend Framework (ZF), I can tell you that using one framework over the other will not solve any problem you might be having.
If you are looking for the added functionality provided by the ZF components, such as a ready-made class for Date or the Form verification class, know that you can use ZF components in Code Igniter. You will need to create a special class in CI that will jumpstart the ZF class autoloader. From there you can simply include ZF classes and use them as if you were inside a ZF application.
See http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/ and http://fr.slideshare.net/samsonasik/codeigniter-using-third-party-components-zend-framework-components for more details.
"Integrate" means you want to put your app running on CodeIgniter withing ZendFramework. So basically you changed nothing and there's no much sense of doing so.
You perhaps could consider porting your app from CI to ZF, but that will require rewriting of your code. But I'd first try to find out what the bottleneck in your app really is and ensure that you will benefit from the switch