CakePHP2でTwitterのクローンサイトを作成しています。その中で「Too few arguments to function FollowsController::follow(), 0 passed and exactly 1 expected」というエラーを解決したいです。follow メソッドの引数が足らないという事だと思うのですが、どのように確認して行けばいいかが分かりません。
色々触ったので醜いコードになってるかも知れませんが、ご教授頂けると幸いです。
<?php class FollowsController extends AppController { // public function get_user_Info($id) // { // $profileImage = $this->User->findById($id); // $this->set('image',$profileImage['User']['profile_Image']); // } public function userAction($user) { $user = $this->User->get('User')->getUserRecord($user['username']); if(!$user) {$this->httpNotFound();} $statuses = $this->Status->get('Status')->getPostMessage($user['id']); $state = null; if ($this->_session->isAuthenticated()) { $loginUser = $this->_session->get('user'); if($loginUser['id']!==$user['id']) { $state = $this->State->get('Following') ->isFollowedUser($loginUser['id'],$user['id']); } } } public function follow($following_id) { $id = $this->Auth->user('id'); $uid = $this->Auth->User('user_id'); $this->Follow->create(array('user_id'=> $id,'following_id'=>$following_id)); if ($this->Follow->save()) { $this->redirect('/users/find'); $this->set('follow',$following_id); }else{ $this->Session->setFlash('Not found'); } } } コード
モデル <?php App::uses('AppModel', 'Model'); /** * Follow Model * */ class Follow extends AppModel { public $actsAs = array( 'Follow' ); public function follow() { $sql = " SELECT COUNT(user_id) AS count FROM follows WHERE user_id = :user_id AND following_id = :following_id "; $data= $this->getRecord($sql,array(':user_id'=> $user_id, ':following_id'=>$following_id)); if($data['count']!=='0') { return true; } return false; } } コード
ビュー <h2><?php print $this->escape($user['username']); ?></h2> <?php if (!is_null($followstate)): ?> <?php if ($followstate): ?> <p>Already followed</p> <?php else: ?> <form action="<?php print $base_url; ?>/follow" method="post"> <input type="hidden" name="_token" value="<?php print $this->escape($_token); ?>" /> <input type="hidden" name="follow_user_name" value="<?php print $this->escape($user['user_name']); ?>" /> <input type="submit" value="Subscribe" /> </form> <?php endif; ?> <?php endif; ?> <div id="statuses"> <?php foreach ($statuses as $status): ?> <?php print $this->render('blog/status', array('status' => $status)); ?> <?php endforeach; ?> </div> コード
あなたの回答
tips
プレビュー