MVC Right separation for functional component - php

I am building a Web application that allow people to subscribe to certain classes which are divided by semesters.
In one of my interface I have a list of all activities that act as a summary in the backend interface. I was looking to group them by semester and browse through a sequential navigation.
My problem is, where should I put my code since I want it to be easy to maintain and I want to respect the right MVC structure.
Here are my Ideas:
Get the param value in the controller, get the previous and next semester through an
action helper, send the data to the view and then display it
or
Get the param value in the controller, sent it to the view, let the view (through a
view helper) find the previous and next semester and then display it
I have a class that is able to find the semesters through calculation (so it's not in my models)

The first option. Your question is unclear to me, but your first option sounds the closest to what I would do.

Related

multiple controllers for one view php mvc design

I am very new to MVC.
I just finished reading a book and am trying to implement what I have learned, but I am stuck. In the book and some other explanations I have read online, it's always one controller for one view, like navigation view being controlled by its controller, login form controlled by its own controller.
But I have a header with couple of navigation links, and a search form. Do I separate navigation from searching or assume searching is part of navigation and just control them all in one controller?
First of all, you seem to have the impression that "template" and "view" is the same thing. It's wrong. A properly done view will juggle multiple templates and choose which combination to use based on the current state of the model layer.
As for your navigation & search thing ... well ... it's confusing. Each link in navigation would point to either a different controller entirely or a different methods of controller. And search query would definitely be submitted to a separate controller/view pair.
The navigation+search is just a template, that is used in multiple views as part of the complete response.

Where to place common code in Phalcon-based site that is called each page load

I have code that I want to run on every page load, such as looking up menu items, looking up the users details etc. These will be displayed on partial views that make up the main view.
Where do I place this code so that it can fill my partial views with each page load? I know I can just add the code to the top of the partial view itself, but this doesn't really follow the MVC pattern.
Is there a function that is always called that I can hook into in my base controller?
You can create a base viewmodel for the repeated code and make other viewmodels inherit from it.
...such as looking up menu items, looking up the users details etc
You're a bit unclear about the type of information you want to load: in case the info is a view-component then indeed you should create a base-view and inherit from it or include it (composition) in any other view.
But, in case it is "user-information" - the data should live in a model-component that again, may live as "base-model" object that is included in other model components.

MVC : Dynamic action links in a view: where to put the business logic (zend2)

So, I am fairly new to Zend 2 and MVC as a whole, and I find myself in a situation where I want to follow best practices to make my code reusable and easy to understand.
The particular scenario I want to deal with is the following. Let's say I am writing an editorial application, where users can send articles, but they need to be approved before they are published. When you access an article /article/view/101 , you get a page with the article info on one side (Status, Author, Date, Title, Body) and on the sidebar you get a set of actions.
The set of actions (links) changes based on the type of user viewing the article (guest, user, reviewer or admin) and also based on the status of the article (draft,finished,published)
So the question is: Where do on the MVC model do I put the business logic to decide which actions (links) to put on the sidebar?
The controller does not seem appropriate because I would be adding Business Logic there, and also adding HTML (bad + bad)
The view does not work either because I would be adding business logic.
A service doesn't seem to work either because it seems I would be either adding HTML, or calling partials from there, and that should not be done either...
The only thing I could think of is doing the Business Logic in a service or helper (since more than one model is needed, article and user) and return an 'array' of actions (no HTML). Then the view processes those to actually get the HTML, but I'm not sure if that is the way to do it, and wanted some experienced input.

When using MVC in PHP,Should 1 Controller be able to load a entire dynamic user profile?

Im almost scared to ask questions around here these days because I useually get flammed on and told my question is dumb, but here it goes anyways...
Im new to MVCs and im starting to get the hang of them, but one thing im unsure about is if 1 controller is suppose to load a entire profile that has multiple components (i.e a notification beacon, a friend feed, a list of friends that displays thumbnails , a place to post statuses ect...)for the purposes of this post assume im asking if alll the loading for a entire facebook profile should be done in one controller?
Or do i separate each dynamic component into its own MVC and then glue them all together in one main controller or....?
another idea i had was that maybe u do separate each component , but instead of having one main controller you call them as needed in the index.
You could use one controller for the Profile (using your example) and have multiple models fetch and process all the data you need to show. This way even a big page can result in an easy to understand controller that is not so big.

PHP : inheritance logical (extends)

This may sound as a non related coding question but it's directly related :
The facts: I've developped a website (with symfony) which allows players to search for a team (like a job board). It makes one module only.
The problems I want the website to be even more accurate and make a custom form for each players depending on the game (for example, for those who play "league of legends" they'll have 3 more informations to fill up....)
The solutions?
One module per game (example: http://pastie.org/private/cl48jsrjreukyjmj7jrk8a).
I'm currently developping 1 module per game in order to take in consideration the specific criteria for specific games.
Advantages :
The player enters the informations in relation with his game and does not see/interact the other criteria
Disavantages:
90% of the code are the same between each modules. It takes more time.
Inheritance
I never played with that before so i don't know if it's possible in my case to stick with 1 module for the entire game collection AND taking in consideration the specific criterias for games. In that case it would mean to have 1 template per game and displaying the right template with the right accessors like
($this->getCV()->getPseudo(); / $this->getCV()->getGame()->getSpecificCriteria1();)
If I have read your question correctly, you want to show additional fields for each specific game.
Solution 1
Create a 2 form process. After your first form, you could redirect the user to a second form which depends on their answers. To do this, in your first form, use a redirect to send the user to a game-specific second form.
Solution 2
Pass the name of the game to the template and show a customised partial for the extra form fields. For this you will need a Url with a game parameter like this:
www.example.com/form/show/:game_identifier
Then in your action, read the parameter and pass it to your template.
In the template, show a partial dependant on the game that was passed through. So only show the extra fields if a specific game was chosen before hand.
There are further ways to accomplish this but these 2 sprung to mind first.

Categories