1111
1212use Zend \Mvc \Controller \AbstractActionController ;
1313use Zend \View \Model \ViewModel ;
14- // use Album\Form\AlbumForm; // <-- Add this import
15- // use Album\Model\Album; // <-- Add this import
14+ use User \ Model \ User ;
15+ use User \ Form \ PartyForm ;
1616
1717class UserController extends AbstractActionController
1818{
19- protected $ CollectinfoTable ;
19+ protected $ infoTable ;
2020
2121// ...
2222 public function indexAction ()
2323 {
2424 return new ViewModel (array (
25- 'Collectinfo ' => $ this ->getCollectinfoTable ()->fetchAll (),
25+ 'userinfo ' => $ this ->getinfoTable ()->fetchAll (),
2626 ));
2727 }
2828// ...
29+ public function addAction ()
30+ {
31+ $ form = new PartyForm ();
32+ $ form ->get ('submit ' )->setValue ('Add ' );
33+ $ request = $ this ->getRequest ();
34+ if ($ request ->isPost ()) {
35+ $ User = new User ();
36+ $ form ->setInputFilter ($ User ->getInputFilter ());
37+ $ form ->setData ($ request ->getPost ());
38+ if ($ form ->isValid ()) {
39+ $ User ->exchangeArray ($ form ->getData ());
40+ $ this ->getinfoTable ()->save_info ($ User );
41+
42+ // Redirect to list of albums
43+ return $ this ->redirect ()->toRoute ('User ' );
44+ }
45+ }
46+ return array ('form ' => $ form );
47+
48+ }
49+
2950
51+ public function editAction ()
52+ {
53+ $ id = (int ) $ this ->params ()->fromRoute ('id ' , 0 );
54+ if (!$ id ) {
55+ return $ this ->redirect ()->toRoute ('User ' , array (
56+ 'action ' => 'add '
57+ ));
58+ }
59+
60+ // Get the Album with the specified id. An exception is thrown
61+ // if it cannot be found, in which case go to the index page.
62+ try {
63+ $ Party = $ this ->getinfoTable ()->get_info ($ id );
64+ }
65+ catch (\Exception $ ex ) {
66+ return $ this ->redirect ()->toRoute ('user ' , array (
67+ 'action ' => 'index '
68+ ));
69+ }
70+
71+ $ form = new PartyForm ();
72+ $ form ->bind ($ Party );
73+ $ form ->get ('submit ' )->setAttribute ('value ' , 'Edit ' );
74+
75+ $ request = $ this ->getRequest ();
76+ if ($ request ->isPost ()) {
77+ $ form ->setInputFilter ($ Party ->getInputFilter ());
78+ $ form ->setData ($ request ->getPost ());
79+
80+ if ($ form ->isValid ()) {
81+ $ this ->getinfoTable ()->save_info ($ Party );
82+
83+ // Redirect to list of albums
84+ return $ this ->redirect ()->toRoute ('User ' );
85+ }
86+ }
87+
88+ return array (
89+ 'id ' => $ id ,
90+ 'form ' => $ form ,
91+ );
92+ }
93+
94+
95+ // module/Album/src/Album/Controller/AlbumController.php:
96+ //...
97+ // Add content to the following method:
98+ public function deleteAction ()
99+ {
100+ $ id = (int ) $ this ->params ()->fromRoute ('id ' , 0 );
101+ if (!$ id ) {
102+ return $ this ->redirect ()->toRoute ('User ' );
103+ }
104+
105+ $ request = $ this ->getRequest ();
106+ if ($ request ->isPost ()) {
107+ $ del = $ request ->getPost ('del ' , 'No ' );
108+
109+ if ($ del == 'Yes ' ) {
110+ $ id = (int ) $ request ->getPost ('id ' );
111+ $ this ->getinfoTable ()->delete_info ($ id );
112+ }
113+
114+ // Redirect to list of albums
115+ return $ this ->redirect ()->toRoute ('user ' );
116+ }
117+
118+ return array (
119+ 'id ' => $ id ,
120+ 'partyinfo ' => $ this ->getinfoTable ()->get_info ($ id )
121+ );
122+ }
123+
124+ //...
125+
30126 public function fooAction ()
31127 {
32128 // This shows the :controller and :action parameters in default route
@@ -35,12 +131,12 @@ public function fooAction()
35131 }
36132
37133 // module/Album/src/Album/Controller/AlbumController.php:
38- public function getCollectinfoTable ()
134+ public function getinfoTable ()
39135 {
40- if (!$ this ->CollectinfoTable ) {
136+ if (!$ this ->infoTable ) {
41137 $ sm = $ this ->getServiceLocator ();
42- $ this ->CollectinfoTable = $ sm ->get ('User\Model\UserTable ' );
138+ $ this ->infoTable = $ sm ->get ('User\Model\UserTable ' );
43139 }
44- return $ this ->CollectinfoTable ;
140+ return $ this ->infoTable ;
45141 }
46142}
0 commit comments