質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

0回答

316閲覧

CakePHP2でToo few arguments to function FollowsController::follow(), 0 passed and exactly 1 expected

amaturePy

総合スコア131

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2019/06/19 15:17

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> コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問