PHP Projects · Lesson 3 of 8
Todo Application
Model tasks with ownership, validation, and explicit state changes.
Lesson
A todo app needs a task model, create and update validation, and a clear completed state. Persist tasks with an owner identifier and filter every read or write by the authenticated owner. Use CSRF protection for actions and escape task titles in the interface.
The persistence query should scope updates to both task and owner.
Further guidance
Turn the feature into a sequence of small vertical slices: input, validation, domain behavior, persistence, response, and tests. Write acceptance criteria before implementation, protect each operation with authorization, and verify invalid input and failure cases. Document setup and keep deployment secrets out of the repository.
Practice task: Create a fresh example for Todo Application. Predict the result before running it, then change one input and explain why the result changes. Test a normal case and one boundary or invalid case where it applies. Compare your output with the example and note one rule you would use in a real project.
Code examples
Todo Application
PHP
$statement = $pdo->prepare(
'UPDATE tasks SET is_complete = 1 WHERE id = :id AND user_id = :user'
);
$statement->execute(['id' => $taskId, 'user' => $userId]);
Expected output
Only the current user’s matching task can be completed
Key points
- Model tasks with ownership, validation, and explicit state changes.
- Build and verify one complete feature at a time.
- Test invalid input, permissions, and failure paths before deployment.
Your learning progress
Finish this lesson
Optional practice
PHP playground
This site does not execute learner-provided PHP code. Connect a secured PHP sandbox service before enabling code execution.
Execution is disabled. No code is sent to a server.