Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am doing a laravel project and want to be able to read a GET Parameter from the URL on each Page. With this optional parameter (url?color=blue) i want to switch between two differen color shemes.
This parameter should be accessable from each page. My function is already prepared and works pretty good. But of course, i won't place this function on each controller and / or view.
So my question is: Is there any posibility to place this function on a central component? Where should i place it?
Session
Perhaps you should consider saving this variable in a session? See the Laravel documentation about this. Sessions provide a way to store information about the user across multiple requests. This seems a solution to what you're trying to achieve persisting the query parameter for every request.
Middleware
To answer your question: you could probably write Middleware to interact with this query parameter. Though it seems counter-intuitive for your use case.
The implementation depends on what you would lke to do with the variable.
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 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 8 years ago.
Improve this question
After a bit of research I think its better if I ask for help to a specific problem, because I think if I am to learn the skills needed, I'd be taking on another language, and I can't get into the details of htaccess and regular expression at the moment, hopefully someday.
What I have now in URL is (localhost/site/controller/function/$arg1)
What information do I need to place into the htaccess so the controller and function isn't displayed. But the end result is (localhost/site/$arg1).
I think, this doesn't really make sense. As stated in the comments, you can use mod_rewrite to send your shortened URLs to the controller, but controller and function need to be static. So having a separate function doesn't really help, controller should be enough.
One thing you could do is selecting the RewriteRules in your .htaccess depending on the $arg1 using for example RewriteCond. That way you could send different URLs to different controllers. It depends on your URL structure if this is feasible.
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'm trying to create an age gateway/verification bundle for Symfony2. I'm new to the framework and not sure of the right way to implement it.
So far I have it set-up as a voter but it appears you then have to call isGranted() with a role on every action you want the gateway to show up. The problem is that, at that point, I don't think the user has a role.
This leads me to believe that I should be doing things differently, e.g., firewall or a listener maybe.
Can someone please advise on the best method along with some background info/links to help get me started?
Looking at a an answer to a similar question, a simple way to do this would be to create a twig template which checks for the presence of a cookie using:
{% if app.request.cookies.has('someCookie') %}
If that's not present, then you can inject the required Javascript to display a popup, insert a META REFRESH to force a redirect, or some other action.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i am making an application using mvc structure. In that when the controls go from controller to model step then it comes back. i want that Ajax request should go directly from model to view rather than going to controller and then to view....
Why would you like to use the MVC pattern at all when you then want to ignore it? This does not make any sense at all.
Technically what you want is possible using a dispatcher filter and getting an instance of the model via ClassRegistry but bypassing the controller step disables any kind of auth checks, components and well, views as well. It totally makes no sense.
If you want to build a messy application go for the dispatcher filter or don't use a MVC framework at all.
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 4 years ago.
Improve this question
I'm building an Authentification library that's going to have around 45+ methods for dealing with user related stuff. However I've been wondering if it's actually recommendable to keep everything on a single file.
Is there a benefit on splitting my class into several subclasses and load them when needed?
I can always for example split the class into "mandatory" elements and the elements that only registered users need...
For example:
Mandatory Methods:
$user->is_logged()
$user->login()
$user->register()
Methods for Register...
Methods for logged-in user.
It just depends on how you want to be including the class file(s) in your pages. If you want one simply include() statement for every page, then keep it all in one file. Unless your library is HUGE, the overhead from the other classes shouldn't be too much.
If you do it the other way, you'll simply be including different files based on the status of the session of the client.
Personally, I'd split them up as it's easier to edit them that way, but it's totally up to you.
I'd go with the class/sub-class option.
You could then use a factory to return the correct type of user object based on the current URL or by simply specifying the desired type of user object if your particular setup doesn't lend itself to this.