I believe this to be a relatively simple issue but I have been searching for hours on the forum and have not found
what I am looking for.
I have a form (CGridView) where I use the advanced search to filter the rows returned (AllSites). I then want to allow the
user to click on a button (or a link) and create a copy of the list with their customer id in another table (MySites)
It works fine but my requirements were changed by the user. Now they want to name the list when they create it and want to be able to manage multiple lists. So I added a table "MyList" to the schema.
I have typical CRUD forms for "AllSites", "MyList" and for "MySites"
Table 1: AllSites
(id, name, url)
Table 2: MyList
(id, my_id)
Table 3: MySites
(id, name, url, my_id, list_id)
Form reviewSites.php contains link to controller actionCreateList($myid)
Works great but I don’t know the best place to ask the user for the “listname”.
I could do it in the reviewSites view they are on or navigate to a new form (create a list) then call the function to populate the list.
reviewSites.php
echo CHtml::TextField("Campaign", 'Enter Campaign Name'); //, 'campaign'=>$_POST["Campaign"]
echo CHtml::link('Add Site to List',array('createReviewlist', 'id'=>$id ));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'reviewsite-grid',
'dataProvider' => $model->searchSites($criteria),
'filter' => $model, ....
If it is not part of the model and is just a field on the reviewSites view above the CGridView, how do I pass the value to the controller?
In the controller I do the following:
Read the Parameters for the search
Get the data
Create the list header (default the name currently)
Create the list detail
Controller:
public function actionCreateReviewlist($id) {
$campaign = "Test" ; // $_POST['reviewSites']['Campaign'];
$model = new Website('searchSites');
$model->unsetAttributes();
$params = Yii::app()->user->getState('SiteSearchParams');
if ( isset($params) ) {
$model->attributes = $params;
}
$criteria = new CDbCriteria;
// get the websites that are not in table for that partner
$criteria-> condition = (" t.id NOT IN (select website_id from partner_site where partner_id = ".$id.")");
$dataProvider = $model->searchSites($criteria);
$sites = $dataProvider->getData();
// create campaign
$c = new Campaign;
$c->title = $campaign;
$c->partner_id=$id;
$c->save();
foreach ($sites as $sid) {
// for each site insert a new record.
$ps = new PartnerSite;
$ps->partner_id = $id;
$ps->website_id = $sid->id;
$ps->campaign = $c->id;
$ps->save();
}
$this->redirect(array('reviewlist', 'id'=>$id));
}