I'm new to Zend Framework 2. I successfully completed the Album tutorial for ZF2. Now I'd like to display only a certain data from multiple tables in the database. I have a simple database setup with tables, for example, person, books, status..etc. It's really not important what the database's supposed to do. What I would like to know is if there's a tutorial that would show me step-by-step guidance to display data from table joins. I have seen snippets of codes showing how to do joins, but I haven't found any tutorials on setting up the classes, and how to configure Module.php. In other words, the Module in Album has one table name hardcoded in getServiceConfig(). But how do I set it up so it knows I'm requesting data from multiple tables. Also, if I want to setup the relationship, do I still create class for database tables like in Album tutorial, or is it going to be something different. Can you please help, or show me the right path? If you know of any tutorial that explains handling multiple tables, that would be great.
标签:
zend-framework2
相关问题
- Why does recursive submodule update from github fa
- How to pass options/params to formCollection field
- Compress html output from zend framework 2
- zend smtp mail crashes after 100+ mails
- 404 HTTP errors not being rendered in JSON using Z
相关文章
- Zend Framework 2 Forms Array notation for drop dow
- Use spiffy navigation with zfcrbac module
- Best practice to call another controller action fr
- How to use Zend Service Amazon?
- Difference between init() and onBootStrap() in Zen
- Does Zend Framework 2.0 leave out the amazon s3 li
- Zend Framework 2 Flash Messenger returning no mess
- doctrine migrations 2 + zend framework 2 = is it p
Just to expand on Robs excellent answer, its simple to take it a step further and populate multiple objects to form the relationship you require.
You should also look at hydrating result sets to build your objects for you directly from the ResultSet:
http://framework.zend.com/manual/2.0/en/modules/zend.db.result-set.html
The ablums tutorial uses
Zend\Db\TableGateway
which does not support joining to multiple tables.You need to use
Zend\Db
directly or via a mapper class, such asAbstractDbMapper
within the ZfcBase module.The basic usage looks like this:
The
join()
method is used to perform the join between thealbum
andartist
table. We also usecolumns()
to select which columns are returned. In this case, I create an alias calleda_name
for thename
column within the artist table.Once the
Select
object is set up, then the rest is the standardDb
code that will return aResultSet
object for you containing the data.