Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-10-2007, 01:49 PM
Junior Member
 
Join Date: Dec 2007
Posts: 4
Default Class 'Zend_Db_Table_Abstract' not found

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-10-2007, 02:04 PM
Junior Member
 
Join Date: Oct 2007
Posts: 16
Default

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:
require_once 'Zend/Db/Table/Abstract.php'
This also requires that your PHP include_path includes a path to the Zend Framework library. If you haven't included it then read this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-11-2007, 07:47 AM
Junior Member
 
Join Date: Dec 2007
Posts: 4
Default

" 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:
Example 10.72. Declaring a table class with schema


<?php

// First alternative:

class Bugs extends Zend_Db_Table_Abstract
{
    protected 
$_schema 'bug_db';
    protected 
$_name   'bugs';
}

// Second alternative:

class Bugs extends Zend_Db_Table_Abstract
{
    protected 
$_name 'bug_db.bugs';
}

// If schemas are specified in both $_name and $_schema, the one
// specified in $_name takes precedence:

class Bugs extends Zend_Db_Table_Abstract
{
    protected 
$_name   'bug_db.bugs';
    protected 
$_schema 'ignored';
}
Where should I put the tables classes?
I see that there is a models directory in application, for what it use? where do I use it?
__________________
My Hebrew Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-13-2007, 08:16 AM
Junior Member
 
Join Date: Oct 2007
Posts: 16
Default

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:
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload(); 
Now you can use library classes without require_once, because Zend_Loader includes them for you.

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:
class Webshop_Products extends Zend_Db_Table_Abstract {
...

Save it to your library as a single file: library/Webshop/Products.php.

Now you can use it like this:
PHP Code:
$table = new Webshop_Products();
$product $table->find(123);
... 
...because Zend_Loader automatically looks in the library and includes Webshop/Products.php.

Last edited by troxy : 12-13-2007 at 08:23 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-23-2008, 06:30 AM
Member
 
Join Date: Feb 2008
Posts: 46
Question

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:34 AM.