reGative Posted September 30, 2011 Report Share Posted September 30, 2011 Kāda ir tā shēma? tjip, skatā ir forma, kas aizved uz kontrolleri un tas viss notiek modelī? Quote Link to comment Share on other sites More sharing options...
briedis Posted September 30, 2011 Report Share Posted September 30, 2011 (edited) Kontrolieris saņem datus (POST), padod modelim, modelis saglabā db. Kontrolieris saņem datus no modeļa, padod tos skatam un skats tos attēlo. function action_trolol(){ $view = .. $user = new Model_Users($user_id); $data = $user->getData(); $view->data = $data; $this->request->response->body($view); } Edited September 30, 2011 by briedis Quote Link to comment Share on other sites More sharing options...
reGative Posted September 30, 2011 Author Report Share Posted September 30, 2011 Tātad, kods šāds. Izmantoju tādu metodi ,kā briedis aprakstīja <form action="?post=name" method="post"> <input type="text" name="name" /> </form> <?php if(isset($_GET['post']) and $_GET['post'] == 'name'){ if(!empty($_POST['name'])){ $result; } else{ echo 'Sistēmas kļūda!'; } } ?> skats public function insert_names($name){ $query = DB::query(DATABASE::INSERT, 'INSERT INTO names (name) VALUES (:name)')->parameters(array(':name' => $name)); } modelis $this->template->content = View::factory('about/about')->set('result', Model::factory('index')->insert_names($_POST['name'])); kontrolieris. Met erroru, ka nav nodefinēts kontrolierī $_POST['name']. Quote Link to comment Share on other sites More sharing options...
briedis Posted September 30, 2011 Report Share Posted September 30, 2011 (edited) Tas nav tas ko es aprakstīju. Mana interpretācija: //Kontrolieris action_user(){ $view = new View(..); $view->data = Model_Users::getUser($_POST['user_id']); $this->response->body($view); } //Modelis public static function getUser($user_id){ $data = ... SELECT * FROM users WHERE id = $user_id return $data; } //Skats <html> <body> <form action="<?=Route::get('kontrolieris/user');?>"> Lietotāja id: <input type="text" name="user_id"/> <input type="submit"/> </form> Lietotājvārds: <strong><?=$data->username;?></strong> E-pasts: <strong><?=$data->mail;?></strong> </body> </html> Esi palasījis kaut kādus materiālus par to, kas vispār ir MVC? Edited September 30, 2011 by briedis Quote Link to comment Share on other sites More sharing options...
daGrevis Posted September 30, 2011 Report Share Posted September 30, 2011 Briedi, kas tas par Route::get()? Ja vajag linku, tad URL::site(). Ja to pašu lapu, tad tukšs params. P.S. Ja mēs par Kohana... vai arī tas skaitās pseido-kods? :) Quote Link to comment Share on other sites More sharing options...
briedis Posted September 30, 2011 Report Share Posted September 30, 2011 Briedi, kas tas par Route::get()? Ja vajag linku, tad URL::site(). Ja to pašu lapu, tad tukšs params. P.S. Ja mēs par Kohana... vai arī tas skaitās pseido-kods? :) Nu ok, es uz sitiena neatceros kā bija kohanā, bet doma tieši tāda pati. Jā, vairāk jau laikam pseido-kods, nevis copy-paste strādājošs piemērs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.