click below
click below
Normal Size Small Size show me how
M2 - Web Sys
WEB SYSTEM TECHNOLOGIES / IT0049
| Question | Answer |
|---|---|
| Matching type. Match the term with the correct description. | |
| $table | Tells a Model which database table it represents |
| findAll() | Retrieves every record from a Model's table |
| $allowedFields | Restricts which fields may be mass-assigned during insert or update |
| where() | Filters query results based on a condition |
| _______________________________________________________________________ | _______________________________________________________________________ |
| Which line correctly retrieves all tasks with status 'done' using a TaskModel instance $model? | $model->where('status', 'done')->findAll(); |
| In the typical CodeIgniter data flow, which component calls the Model to retrieve data before passing it to a View? | The Controller |
| What term describes an unauthorized attempt to manipulate a database through injected SQL, which Query Builder helps prevent? | SQL injection |
| The .env file is used to store view templates. | False |
| What is the name of the CodeIgniter file where database connection settings are typically stored? | .env |
| Which method would you chain to where('status', 'pending') to sort results by creation date, newest first? | orderBy('created_at', 'DESC') |
| Which property in a Model tells CodeIgniter which database table the Model represents? | $table |
| CodeIgniter automatically creates database tables the first time a Model is used. | False |
| Every CodeIgniter application must have at least one Model, even if it does not use a database. | False |
| Chaining where() and orderBy() lets you filter and sort a query in a single statement. | True |
| A Model's $allowedFields property lists the columns permitted for mass assignment. | True |
| Which Query Builder method retrieves a single record by its primary key? | find($id) |
| Comparing SELECT * FROM tasks WHERE status = '$status' (built by directly inserting a variable into a SQL string) against $builder->where('status', $status)->get();, which is safer and why? | The Query Builder version, because it automatically escapes the value and reduces SQL injection risk |
| A table has columns id, title, status, created_at. Which line correctly inserts a new row with only a title? | $model->insert(['title' => 'Buy groceries']); |
| The public folder should contain the application's business logic, including Models. | False |
| A developer hardcodes a task list directly inside a controller using a PHP array, even though a database table for tasks already exists. What is the main drawback? | Any change to the task list requires editing code, and the two sources of data can fall out of sync |
| A team stores database passwords directly inside a Model's PHP file instead of .env. What is the main problem with this? | Credentials embedded in code are more likely to be exposed and harder to change per environment than values in .env |
| Why is CodeIgniter's Query Builder generally considered safer than concatenating raw SQL strings with user input? | Query Builder automatically escapes values, reducing the risk of SQL injection |
| What is the primary purpose of a CodeIgniter Model? | To manage data and communicate with the database |
| Using Query Builder instead of raw SQL strings reduces the risk of SQL injection. | True |
| findAll() returns only the first matching record from a table | False |
| Which Query Builder method retrieves every record from a Model's table? | findAll() |
| What does the $primaryKey property in a Model define? | The column CodeIgniter treats as the unique identifier for each row |
| After correctly configuring .env and creating a Model, a page still throws a database connection error. Which of these is LEAST likely to be the cause? | The view has no <title> tag |
| Which CodeIgniter file typically stores database connection settings such as hostname, username, and database name? | .env |
| What Query Builder method sorts retrieved records by a specific column, ascending or descending? | orderBy() |
| What term describes the special class that represents and manages a specific database table? | Model |
| A view shows "Undefined variable $tasks" even though the Model successfully retrieves records in the controller. What is the most likely cause? | The controller did not include tasks in the data array passed to view() |
| A new priority column is added directly in the database, but $allowedFields is never updated to include it. What happens when a controller tries to save a priority value through this Model? | It is silently dropped because $allowedFields still does not list it |
| findAll() returns only the first matching record from a table. | False |
| A model defines protected $allowedFields = ['title', 'status']; but a controller tries to insert a record that also includes a description value. What happens? | The description value is silently ignored because it is not in $allowedFields |
| A page correctly lists all tasks, but clicking into one specific task shows "Undefined variable $task." The controller has: $data['tasks'] = $model->find($id); return view('tasks/show', $data);. What is the bug? | The single record is stored under the plural key 'tasks' but the view expects $task (singular) |
| What does a Model's $allowedFields property control? | Which fields may be mass-assigned during insert() or update() |
| What does a Model's $allowedFields property control? | Which fields may be mass-assigned during insert() or update() |