2013-11-25 10:39:48 3929次浏览 1条回答 0 悬赏 50 金钱

我在添加 这个action到ProjectController类的时候   显示

Missing argument 1 for ProjectController::loadModel(), called in /home/wwwroot/trackstar/protected/controllers/ProjectController.php on line 197 and defined


public function actionAdduser() 

{

<span class="php-hl-var" style="color: blue;">$form</span><span class="php-hl-code" style="color: gray;">=</span><span class="php-hl-reserved" style="font-weight: bold;">new</span> <span class="php-hl-identifier" style="color: green;">ProjectUserForm</span><span class="php-hl-code" style="color: gray;">; 
</span><span class="php-hl-var" style="color: blue;">$project</span><span class="php-hl-code" style="color: gray;"> = </span><span class="php-hl-var" style="color: blue;">$this</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">loadModel</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-code" style="color: gray;">;</span><span class="php-hl-code"><span style="color:#ff0000;">// 这一段的loadModel() 上面的函数只有 loadModel($id),</span></span><span class="php-hl-code" style="color: gray;">
</span><span class="php-hl-comment" style="color: rgb(128, 128, 128); font-style: italic;">//</span><span class="php-hl-comment" style="color: rgb(128, 128, 128); font-style: italic;"> collect user input data</span>
<span class="php-hl-reserved" style="font-weight: bold;">if</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-reserved" style="font-weight: bold;">isset</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-var" style="color: blue;">$_POST</span><span class="php-hl-brackets" style="color: olive;">[</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-string" style="color: red;">ProjectUserForm</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-brackets" style="color: olive;">]</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-brackets" style="color: olive;">)</span> <span class="php-hl-brackets" style="color: olive;">{</span>
    <span class="php-hl-var" style="color: blue;">$form</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">attributes</span><span class="php-hl-code" style="color: gray;">=</span><span class="php-hl-var" style="color: blue;">$_POST</span><span class="php-hl-brackets" style="color: olive;">[</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-string" style="color: red;">ProjectUserForm</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-brackets" style="color: olive;">]</span><span class="php-hl-code" style="color: gray;">; 
    </span><span class="php-hl-var" style="color: blue;">$form</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">project</span><span class="php-hl-code" style="color: gray;"> = </span><span class="php-hl-var" style="color: blue;">$project</span><span class="php-hl-code" style="color: gray;">; </span><span class="php-hl-comment" style="color: rgb(128, 128, 128); font-style: italic;">//</span><span class="php-hl-comment" style="color: rgb(128, 128, 128); font-style: italic;"> validate user input and set a sucessfull flassh message if valid</span>
    <span class="php-hl-reserved" style="font-weight: bold;">if</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-var" style="color: blue;">$form</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">validate</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-brackets" style="color: olive;">)</span> 
    <span class="php-hl-brackets" style="color: olive;">{</span>
        <span class="php-hl-identifier" style="color: green;">Yii</span><span class="php-hl-code" style="color: gray;">::</span><span class="php-hl-identifier" style="color: green;">app</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">user</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">setFlash</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-string" style="color: red;">success</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-code" style="color: gray;">,</span><span class="php-hl-var" style="color: blue;">$form</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">username</span><span class="php-hl-code" style="color: gray;"> . </span><span class="php-hl-quotes" style="color: red;">&quot;</span><span class="php-hl-string" style="color: red;"> has been added to the project.</span><span class="php-hl-quotes" style="color: red;">&quot;</span> <span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-code" style="color: gray;">;
        </span><span class="php-hl-var" style="color: blue;">$form</span><span class="php-hl-code" style="color: gray;">=</span><span class="php-hl-reserved" style="font-weight: bold;">new</span> <span class="php-hl-identifier" style="color: green;">ProjectUserForm</span><span class="php-hl-code" style="color: gray;">;
    </span><span class="php-hl-brackets" style="color: olive;">}</span>
<span class="php-hl-brackets" style="color: olive;">}</span>
<span class="php-hl-comment" style="color: rgb(128, 128, 128); font-style: italic;">//</span><span class="php-hl-comment" style="color: rgb(128, 128, 128); font-style: italic;"> display the add user form </span>
<span class="php-hl-var" style="color: blue;">$users</span><span class="php-hl-code" style="color: gray;"> = </span><span class="php-hl-identifier" style="color: green;">User</span><span class="php-hl-code" style="color: gray;">::</span><span class="php-hl-identifier" style="color: green;">model</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">findAll</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-code" style="color: gray;">; 
</span><span class="php-hl-var" style="color: blue;">$usernames</span><span class="php-hl-code" style="color: gray;">=</span><span class="php-hl-reserved" style="font-weight: bold;">array</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-code" style="color: gray;">; 
</span><span class="php-hl-reserved" style="font-weight: bold;">foreach</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-var" style="color: blue;">$users</span> <span class="php-hl-reserved" style="font-weight: bold;">as</span> <span class="php-hl-var" style="color: blue;">$user</span><span class="php-hl-brackets" style="color: olive;">)</span> 
<span class="php-hl-brackets" style="color: olive;">{</span>
    <span class="php-hl-var" style="color: blue;">$usernames</span><span class="php-hl-brackets" style="color: olive;">[</span><span class="php-hl-brackets" style="color: olive;">]</span><span class="php-hl-code" style="color: gray;">=</span><span class="php-hl-var" style="color: blue;">$user</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">username</span><span class="php-hl-code" style="color: gray;">;
</span><span class="php-hl-brackets" style="color: olive;">}</span>
<span class="php-hl-var" style="color: blue;">$form</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">project</span><span class="php-hl-code" style="color: gray;"> = </span><span class="php-hl-var" style="color: blue;">$project</span><span class="php-hl-code" style="color: gray;">; 
</span><span class="php-hl-var" style="color: blue;">$this</span><span class="php-hl-code" style="color: gray;">-&gt;</span><span class="php-hl-identifier" style="color: green;">render</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-string" style="color: red;">adduser</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-code" style="color: gray;">,</span><span class="php-hl-reserved" style="font-weight: bold;">array</span><span class="php-hl-brackets" style="color: olive;">(</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-string" style="color: red;">model</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-code" style="color: gray;">=&gt;</span><span class="php-hl-var" style="color: blue;">$form</span><span class="php-hl-code" style="color: gray;">, </span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-string" style="color: red;">usernames</span><span class="php-hl-quotes" style="color: red;">'</span><span class="php-hl-code" style="color: gray;">=&gt;</span><span class="php-hl-var" style="color: blue;">$usernames</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-brackets" style="color: olive;">)</span><span class="php-hl-code" style="color: gray;">; 

}

函数就只有这个

public function loadModel($id)
{
$model=Project::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

求问应该怎么改

最佳答案

  • icultivator 发布于 2013-11-25 12:19 举报

    亲,应该这么调用:$this->loadModel($id)

    1 条回复
    回复于 2013-11-26 10:35 回复

    谢了 我搞定了 加这两个就好了
    public function actionAdduser($id) //
    {

    $form=new ProjectUserForm; 
    $project = $this->loadModel($id);
    

    ...
    }

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
MK.Elias
试用期

MK.Elias

注册时间:2013-11-25
最后登录:2013-12-25
在线时长:3小时50分
  • 粉丝0
  • 金钱0
  • 威望0
  • 积分30

热门问题