|
|||
|
What do I need to include in order to use 'Zend_Db_Table_Abstract'?
It is not write in the documentation: Zend Framework: Documentation It is in the db section but I include the "Zend/Db.php" and I success to query in it.
__________________
My Hebrew Blog Last edited by nadavvin : 12-10-2007 at 01:51 PM. |
|
|||
|
The Zend Framework is designed on the principle that each class is stored as a separate file, where the filename reflects the classname.
So in order to use Zend_Db_Table_Abstract, you'll need to include the file Zend/Db/Table/Abstract.php, like this: PHP Code:
|
|
|||
|
" The Zend Framework is designed on the principle that each class is stored as a separate file, where the filename reflects the classname."
If so I need to create php file for each table class that I use butin the tutorial they use all the table classes in the same script: Zend Framework: Documentation PHP Code:
I see that there is a models directory in application, for what it use? where do I use it?
__________________
My Hebrew Blog |
|
|||
|
It's a matter of taste where you put your model files.
Personally I put them in the library, next to the Zend folder. You can use the handy tool Zend_Loader to load your files dynamically. It's highly recommended! In your bootstrap file, add the following lines: PHP Code:
So for example, if you're building a webshop you first create your own namespace in the library folder like this: library/Webshop. Here's an example of a model: PHP Code:
Now you can use it like this: PHP Code:
Last edited by troxy : 12-13-2007 at 08:23 AM. |
|
|||
|
As per the discussion, i hv created the Table Class and saved the table class under library->Tables(new folder)->user.php.
class User extends Zend_Db_Table_Abstract { protected $_schema = 'zfwork';// DB name protected $_name = 'user';// Table name protected $_primary = 'ID';// primary key setting. } Here do i need to give the other fields(email,phone) also? or not required? ----------------------- And added the below code to do autoloading of required class. require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); IN the bootstrap file(index.php). Then the below statment is required for table operation? "require_once 'Zend/Db/Table/Abstract.php';" ----------------------- While using the below code in the controller page (UserController.php) in the listAction() function, i am not getting the output. Can you plz tell me where is the error and whats the problem? Because its confusing. $table = new Tables_User(); $users = $table->find(2); print_r($users); ----------------------- One more thing is, for DB connection i am using the following code and connected successfully. My question is, if i hv the DB connection then why should i use a separate "Table Classes" like above. And plz tell me the importance of this also. $options = array('host'=> 'localhost', 'username'=> 'developer', 'password'=> 'success', 'dbname'=> 'test' ); $db = Zend_Db::factory('Pdo_Mysql', $options); ----------------------- Please explain the above DB & Table functionality questions with some example. Last edited by murugesanme : 02-23-2008 at 06:34 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|