public function actionChannel() { $todo = array(); $filename = './public/channel.txt'; $result = file($filename); $result = array_map('check', $result); $specialChar = ':'; $pid = 0; $i = 1; foreach ($result as $item) { $todo[$i]['name'] = str_replace($specialChar, '', $item); $todo[$i]['id'] = $i; $todo[$i]['weight'] = rand(1, 9); $todo[$i]['description'] = '此频道提供' . $todo[$i]['name'] . '相关信息'; $todo[$i]['charge'] = 1; $todo[$i]['uid'] = 1; if (strpos($item, $specialChar)) { $todo[$i]['pid'] = 0; $pid = $i; } else { $todo[$i]['pid'] = $pid; } $i++; } foreach ($todo as $item) { $channels = new Channels(); $channels->id = $item['id']; $channels->name = $item['name']; $channels->weight = $item['weight']; $channels->description = $item['description']; $channels->charge = $item['charge']; $channels->uid = $item['uid']; $channels->pid = $item['pid']; if ($channels->save()) { echo 'ok' . $channels->id . "<br />"; } else { echo CHtml::errorSummary($channels); } } UtilHelper::dump($todo); }