Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I always use controller files for my project. Sometimes i get confused when to create libraries. Can you please let me know when do we create libraries files and for what purpose?
I can simply define as following:
Controller: This entry point of your application which is associated with URI.
Helper: Helpers are written in procedural format rather than OOP format. Small scale tweaking is handled by this. As the name suggest Helper file helps the main application controllers in some ways.
Library: Libraries are conventionally reusable code which can be used over different projects.
So if you want to write a library that should be reusable and generic. or it will be a waste of time and effort.
When you need to use any code for several portion or projects, you can create library for better understanding and easy access. Suppose, you want to use any user defined captcha generating function, you can create a library and can use it for several projects.
When you are writing some code that is not specific to current project only and it can be reused on other projects then you should create a library.
For example, I have some generic controllers that I use in every project, I put them in libraries and load via __autoload.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm having a trouble on how to implement Single Page Application on Laravel blade php file format using Vue-router, is that possible?.The reference link below says that it is impossible to use SPA on php file format and I'm here to ask to confirm if this is not possible, but I guess there is other solution with this issue. It would be great if anybody could figure out, thank you so much in advance!.
Reference
For example with this file it should blade.php instead of vue
Not possible ..laravel have some standards that need to follow
Blade view files use the .blade.php file extension and are typically stored in the resources/views directory.
SPA are fast since most resources (HTML,CSSS,Scripts etc) and DOM components are only loaded once throughout the entire cycle of an application. Subsequently, only dynamic content is loaded by JS, which speeds up the site remarkably.
If you are using blade then it needs to reload for every changes to reflect then what points of using it
Refer this: https://laravel-news.com/using-vue-router-laravel
Personally I would opt for L8 with inertiajs(vuejs) which is integrated in the documentation and you can easily make a SPA
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am just getting started with Ajax, and I wonder how to organize my ajax scripts and php files (which process the ajax function).
With Php it was easy, one functions library functions.php with all my classes and methods that I can call whenever I need them.
My first reflex with Ajax was trying to call an already existing method inside a php class in order to process a contact form but I do believe this is impossible and I need a separate file to do this ?
My question is, do I need to create a different file.js for each ajax script and a file.php for each ajax call ? It can get very messy with a few ajax functions compared to php.
Is there a right way to organize this ?
You definitely should use a php framework !
It will help you to organize your code and will bring to you some helpful features like routing which would solve your problem.
You will define some roots, each linked to a specific controller and your code will be well organized.
I can recommend you Symfony2 :
but there are a lot of which are able to do the job :
http://www.hongkiat.com/blog/best-php-frameworks/
If your application is small you can have a look to silex which is a light version of Symfony
To define your urls, you can use a REST api which is a best practice.
I can understand that you find the learning curve of the frameworks difficult but you will not regret it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I found a similar questions, but it's not exactly what I am looking for.
I write web site using php. For dynamic content I use jQuery Ajax.
I have 20-50 functions and I want to use Ajax to call these functions and take JSON.
Idea is to pass parametres via ajax POST. Pages works with database and job is done.
The question - how better organize it?
Should I create 50 separate pages like:
mysite.com/ajax/delete_project.php
mysite.com/ajax/delete_user.php
mysite.com/ajax/show_user_info.php
mysite.com/ajax/show_my_messages.php
mysite.com/ajax/show_my_tasks.php
mysite.com/ajax/send_message.php
.......
or create one page? or maybe i am completely wrong with all of that
Ideally you should be using a framework, such as Symfony. Otherwise, I usually keep all the functions for each content type in a single file. So you might have:
mysite.com/api/blog_posts.php which would implement GET, POST, PUT, DEL, etc... for all the blog posts. Meanwhile, mysite.com/api/messages.php would handle that for all messages.
You must start using an MVC framework if not using already. I would say Laravel should be a good choice, it's easy to learn, feature-rich and fun to work with. Start looking into Laravel Routes.
Moving to MVC is the best way to start getting into shape in your case.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I dont't want to use any framework, but I need a Frontcontroller, Where I can get HELP?
I would recommend building a dynamic invocation front controller. This is what the frameworks use. Here is a link to get started.
http://www.phpwact.org/pattern/front_controller
This book has a great chapter on Presentation Patterns during which he covers the front controller pattern.
PHP Objects, Patterns and Practice, Third Edition (Expert's Voice in Open Source)
http://amzn.to/d3eU0r
You should configure your mod rewriting. All requests should be go to index.php. And not domain part should be send to the GET parameter. For example: example.com/tratata/tratata.
print_r($_GET) should contains 'tratata/tratata';
Create class, which will be explode this GET parameter. It is your FrontController.
Create class tratataController.
Load class by get Parameter.
Sorry for my english.
Pick a framework and look at the implementation of their FrontController. Figure out how it works and build your own.
That said, why on earth would you not want to use a framework? The only reason I can think of is that you want to know how it works. And for that just google and look at existing sources.
I have had the same issue, so I made my own. It's tiny, as the name suggests, and (hopefully simple to use. You just need to make sure that the correct Apache rewrite rules are in place. You can find the source on GitHub. https://github.com/samuelwilliams/Tiny-Front-Controller
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am not trying to create yet another web framework.
For one of the applications I am working on, I want to create a custom framework. I don't want to use any already available framework.
What are the common things to consider?
What should be the architecture?
Thanks :)
If the point of a framework is to make tedious things easy, a good start would be to consider what is tedious.
What are the common things to consider?
Purpose. Usually, when you start building a piece of software, you have a purpose in mind. What will it do that other programs can't?
If you can't answer that question, then take any existing open source framework, change its name and your job is done. Now you have your own framework.
Well if you are going to write a custom framework then I assume the framework needs to be tailored to your needs, otherwise you would use one that is already available. So figure out what your needs are and go from there ;)
What are the most often repeated operations in your application? Is there a division of labor that a framework could make more apparent?