Hoan Dang
Hoan Dang

Reputation: 374

Invoke action in Yii

This is my scenario. A home page with a upload form, user upload the images and submit, then the controller will catch the data from user, add it in the Model. Finally the image info will display in the another page.

I put the actionIndex() in the siteController to render the home page, the actionUpload() in the same file to handle the data user. So in the view, what should I put in the form action to invoke the actionUpload(). I think the flow is quite weird in Yii when I read the blog demo code, I just follow same way with the ASP.NET MVC. Suggest me the right way, plz. Thanks

Upvotes: 0

Views: 3374

Answers (1)

Eirik Hoem
Eirik Hoem

Reputation: 1310

Depends on how you build your form. If using CHtml, do the following:

<?= CHtml::beginForm($this->createUrl('site/upload'))?>

If you have a model that sits behind it:

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'login-form',
        'action' => $this->createUrl('site/upload'),
)); ?>

Please check the Yii documentation and examples on how to properly set up forms. You have several choices here.

Upvotes: 4

Related Questions