CakePHP вопросы и ответы для интервью
Вопрос 11. What is the purpose of the CakePHP 'belongsTo' association?
'belongsTo' association is used to define relationships where a model 'belongs to' another model.
Example:
// class Comment extends AppModel {
public $belongsTo = 'Post';
}
Вопрос 12. Explain the use of the 'security' component in CakePHP.
The 'security' component provides methods to help secure your application, including CSRF protection and form tampering prevention.
Example:
// $this->loadComponent('Security');
Вопрос 13. How to handle file uploads in CakePHP?
You can use the 'FormHelper' and 'File' model to handle file uploads in CakePHP.
Example:
// Form in the view
= $this->Form->create($article, ['type' => 'file']) ?<
Вопрос 14. What is the purpose of the CakePHP 'beforeSave' callback?
The 'beforeSave' callback is called before a record is saved to the database. It's commonly used for data manipulation or validation before saving.
Example:
// public function beforeSave($options = []) {
// Code here
}
Вопрос 15. Explain the use of the CakePHP 'hasMany' association.
'hasMany' association is used to define a one-to-many relationship between models.
Example:
// class Author extends AppModel {
public $hasMany = 'Book';
}
Самое полезное по оценкам пользователей: