Are there any potential pitfalls or drawbacks to fetching the DB adapter from Zend_Registry in every model in ZendFramework?
Fetching the DB adapter from Zend_Registry in every model can lead to tight coupling and make it difficult to unit test the models in isolation. To solve this issue, it's better to inject the DB adapter into the models through their constructors or setter methods.
class MyModel
{
protected $db;
public function __construct(Zend_Db_Adapter_Abstract $db)
{
$this->db = $db;
}
// Rest of the model code here
}
Keywords
Related Questions
- How can server-side variables be effectively utilized when including PHP scripts in HTML pages to pass additional parameters to the included script?
- How can PHP frameworks like phpkit help simplify the process of creating member profiles with customizable features?
- What are the best practices for handling user input and form submissions in PHP to prevent SQL injection attacks?