php-mvc | Project created in the course https | Learning library
kandi X-RAY | php-mvc Summary
kandi X-RAY | php-mvc Summary
Project created in the course
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Add a new User
- Change user s password
- Edit a post
- Bind a value to the statement
- Add a post
- Update a post
- Register a new user
- Add new user
- Show the main network .
- Load view file
php-mvc Key Features
php-mvc Examples and Code Snippets
Community Discussions
Trending Discussions on php-mvc
QUESTION
I have been trying to learn about MVC pattern (without frameworks), however no matter material I read on the Internet, it just seems to be contradicting itself all the time.
My project right now consists of a form that can be submitted in order to add an element to the database. Another page just lists all the elements that are on the database.
So as I understand, my model should connect to the database (or just take the connection as a parameter, something else that was not very clear to me) and have functions like "saveItem" (which takes the $_POST variable as an input and parses it) and "listItems" (which just returns all entries to the page).
However, where does the controller come in? Now I parse my data in the model. But, if that should be rather done in the controller, what does the model actually do? I came across this page. Here, the model only has methods like "select" whose input is just a sql query. But this seems essentially just a PDO wrapper. (Contradicting information in this page about PDO already being a kind-of wrapper and there isn't really any need to do it.)
I guess it kind of makes sense, if the model was written as just a wrapper, it wouldn't actually have anything to do with the specifics of my website. (My understanding now is that each part of mvc is highly specific for each project.)
But then, it seems that either the model or the controller is just unnecessary. Either model parses the data leaving nothing for the controller to do or vice-versa.
I would be deeply grateful for any clarification.
...ANSWER
Answered 2019-May-30 at 08:22I'd take this question rather as a genuine inquiry than a request to review some SEO spam article from Internet. So it goes:
What you need to understand in the first place is that the term "model" is ambiguous. It can represent either the whole application's business logic, or just what you meant - some piece of code that interacts with the database. To avoid this ambiguity, let's stick with the former. It will help you to settle with the Controller. Whereas we will call a "lesser model" a storage. A cover term for a code which actually interacts with the database.
I have a very concise writeup, MVC in simpler terms or the structure of a modern web-application. It will help you to wrap your head around MVC at whole.
Now closer to your question.
A database wrapper cannot be considered a model, in either meaning. A database wrapper is a service used by the storage class. So, you can have at least 3 layers in your application:
- a controller. Just an interface to convey an HTTP client's request to the business model
- a service or a helper. the code which is usually (and wrongly) written in the controller. For example, if you need to register a user, in the controller you are calling a method from a user service, providing the data came from the client.
- a storage class. The actual code to interact with a database. For example it could be a User class that contain methods such as register and such. This class would use PDO (or some more advanced wrapper, or an ORM instance) as a class variable.
Where the latter two should actually encapsulate your whole application's business logic.
The most tricky part here is the instantiation of the Storage class. Given the connection must be done only once, there should be means to instantiate the UserStorage object providing it with the database connection. That is slightly different issue which is solved by means of the Dependency Injection Container
To illustrate the above with a bit of code
QUESTION
I've got the following code snippet from http://requiremind.com/a-most-simple-php-mvc-beginners-tutorial/, however it throws an error:
Parse error: syntax error, unexpected '[' in /usr/home/domains/xyz.pl/public_html/my-soft/routes.php on line 20
on my hosting which has 5.2.17 PHP version.
I searched stackoverflow for a corresponding topic about 5.2 vs 5.4 array differences, but i coudldn't find anything meaningful so I can solve this particulat error (both tables are named), and final resolution should comply with this fact -> table names ('pages', 'posts') are used in conditional statement below the table intitialization.
Could you please advise me on how to solve this without changing the PHP version?
...ANSWER
Answered 2017-Nov-15 at 17:14It looks like they're trying to make a multi-dimensional array.
Try changing the code to this:
QUESTION
I am new to Php mvc design and I have been reading a tutorial, Simple MVC for beginners. In this tutorial the author is routing all calls from the index.php
file based on some link. I have a landing page written in html and was wondering how would i route my, lets say when a user clicks the sign up button, sign up view based on a button not link?
That brings me to another question. Would a controller even be necessary going from a landing page view to a signup view?
views/layout page:
...ANSWER
Answered 2017-Jun-23 at 00:03This is kind of hard to answer as it's not really related to MVC. Hopefully I can give you some insight to point you in the right direction.
MVC is just a concept on how you organise your code. There are many different ways to setup a site which could still be considered MVC.
To put it simply:
- Model: Deals with database logic, one model can be shared by many controllers.
- View: Where your html is (which could include php variables if you aren't using js).
- Controller: Where the logic for your php is. e.g. Mapping an array for your view, going to a different page etc.
Question 1: Your question isn't exactly dealing with the MCV concept itself and more just how html interacts with php.
- You have a link or a button with a link in it.
- This link points to your route which then calls your controller.
- Your controller runs the php logic you need and then serves the html to the user.
Question 2: If you do not have any php in your html view (like an faq page which doesn't require logic) you can just link directly to the page. However it's probably best to go through a controller which just renders the page to keep it consistent.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install php-mvc
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page