Hello,
this are my first steps with ZF, and I'm trying to build up a simple crm.
Now, I do need some help.
In a list (ContactController index action) I want to show:
name, surename, address_1
How can I realize this?
Dump of database:
PHP Code:
CREATE TABLE `adr_address` (
`id` int(10) unsigned NOT NULL auto_increment,
`adr_head_id` int(10) unsigned NOT NULL,
`titel` varchar(20) collate latin1_general_ci default NULL,
`name` varchar(45) collate latin1_general_ci default NULL,
`surename` varchar(45) collate latin1_general_ci default NULL,
`address_1` varchar(45) collate latin1_general_ci default NULL,
`country` varchar(45) collate latin1_general_ci default NULL,
`state` varchar(45) collate latin1_general_ci default NULL,
`zip` varchar(20) collate latin1_general_ci default NULL,
`city` varchar(45) collate latin1_general_ci default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;
INSERT INTO `adr_address` VALUES (1, 1, 'Herr', 'Mueller', 'Max', 'Teststr. 1', NULL, NULL, NULL, NULL, NULL, NULL, '99999', 'Testhausen');
INSERT INTO `adr_address` VALUES (2, 1, 'Herr', 'Mueller', 'Max', 'Teststr. 2', NULL, NULL, NULL, NULL, NULL, NULL, '88888', 'Testhausen 2');
INSERT INTO `adr_address` VALUES (3, 2, 'Frau', 'Meier', 'Lieschen', 'Kokusweg 999', NULL, NULL, NULL, NULL, NULL, NULL, '77777', 'Kokushausen');
INSERT INTO `adr_address` VALUES (4, 2, 'Firma', 'Top Events', NULL, 'Teststr. 3', NULL, NULL, NULL, NULL, NULL, NULL, '55555', 'Testhausen 3');
CREATE TABLE `adr_head` (
`id` int(10) unsigned NOT NULL auto_increment,
`matchcode` varchar(45) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;
INSERT INTO `adr_head` VALUES (1, 'Mueller, Max');
INSERT INTO `adr_head` VALUES (2, 'Meier, Lieschen');
CREATE TABLE `adr_login` (
`id` int(10) unsigned NOT NULL auto_increment,
`adr_head_id` int(10) unsigned NOT NULL,
`name` varchar(20) collate latin1_general_ci NOT NULL,
`pwd` varchar(45) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ;
INSERT INTO `adr_login` VALUES (1, 1, 'admin', 'admin');
content of Controller crm/application/controllers/ContactController.php
PHP Code:
<?php
class ContactController extends Zend_Controller_Action
{
function init()
{
$this->initView();
Zend_Loader::loadClass('Contact');
$this->view->baseUrl = $this->_request->getBaseUrl();
$this->view->user = Zend_Auth::getInstance()->getIdentity();
}
function preDispatch()
{
...
}
function indexAction()
{
$this->view->title = "Kontakte";
$contact = new Contact();
$this->view->contacts = $contact->fetchAll();
$this->render();
}
function detailAction()
{
...
}
function addAction()
{
...
}
function editAction()
{
...
}
function deleteAction()
{
...
}
}
content of crm/application/models/Contact.php
PHP Code:
<?php
class Contact extends Zend_Db_Table
{
protected $_name = 'adr_head';
}
content of crm/application/views/scripts/contact/index.phtml:
PHP Code:
<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<p><a href="<?php echo $this->baseUrl ?>/contact/add">new Contact</a></p>
<table>
<tr>
<th width="30" align="left">ID</th>
<th width="130" align="left">Matchcode</th>
<th width="80">Name</th>
<th width="80">Surename</th>
<th width="100">Street</th>
<th> </th>
</tr>
<?php foreach($this->contacts as $contact) : ?>
<tr>
<td align="left"><?php echo $this->escape($contact->id);?></td>
<td align="left"><?php echo $this->escape($contact->matchcode);?></td>
<td>adr_address.name:</td>
<td>adr_address.surname:</td>
<td>adr_address.address_1:</td>
<td>
<a href="<?php echo $this->baseUrl ?>/contact/detail/id/<?php echo $contact->id;?>">details</a>
<a href="<?php echo $this->baseUrl ?>/contact/edit/id/<?php echo $contact->id;?>">change</a>
<a href="<?php echo $this->baseUrl ?>/contact/delete/id/<?php echo $contact->id;?>">delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $this->render('footer.phtml'); ?>
Thanks for help.