function call_a_singer() { $person = new Singer(); $name = $person->getName(); echo $name; //Prints John }
public function actionArtist() { $singer_id = 1; //сюди передати id виконавця $exist = false; if ($singer_id) { $exist = Singer::model()->selectBySingerId($singer_id); //error_log(var_export($exist,1)); } $model = new Image(); //$user_id = Yii::app()->user->getId(); echo CJSON::encode($this->renderPartial('artist', array('poster' => $model, 'singer_id' => $singer_id, 'exist' => $exist), true, true)); Yii::app()->end(); }
public function selectBySingerId($singer_id) { $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'id=:singer_id'; $criteria->params = array(':singer_id' => $singer_id); $result = Singer::model()->find($criteria); $image = Image::model()->selectByRow('singer', $singer_id); $style = Style::model()->selectBySingerId($singer_id); $result = $result['attributes']; if ($image) { $result['path'] = $image->path; } if ($style) { $result['style'] = $style; } return $result; }
<BODY> <?php class Human { public $tall = 10; public $weight = 20; public function PRIVACY($tall1, $weight1) { $this->tall = $tall1; $this->weight = $weight1; } public function SHOWPRIVACY() { "私の身長は" . (print $this->tall . "<br>"); "私の体重は" . (print $this->weight . "<br>"); } } class Singer extends Human { public function clear() { $this->tall = ""; $this->weight = ""; } } $newSinger = new Singer(); $newSinger->clear(); $newSinger->SHOWPRIVACY(); ?> </BODY> </HTML>
public function run() { $model = new Singer(); $exist = $model->findByAttributes(array('id' => Yii::app()->request->getPost('singer_id'))); if ($exist) { $model = $exist; $row_id = $model->id; } else { $model->name = Yii::app()->request->getPost('name') ? Yii::app()->request->getPost('name') : 'noname'; $model->user_id = Yii::app()->user->getId(); if (!($row_id = $model->Add())) { echo CJSON::encode(array('status' => 'error')); Yii::app()->end(); } } switch (Yii::app()->request->getPost('object')) { //редагуєм текстові поля case 'name': $this->edit_element($model, 'name', Yii::app()->request->getPost('name')); break; case 'description': $this->edit_element($model, 'description', Yii::app()->request->getPost('description')); break; case 'site': $this->edit_element($model, 'site', Yii::app()->request->getPost('site')); break; } if (Yii::app()->request->getPost('object') == 'poster') { //редагуєм постер $poster = new Image(); $exist = $poster->findByAttributes(array('table' => 'singer', 'row_id' => $row_id)); if ($exist) { $poster = $exist; $new = false; } else { $new = true; } $poster->image = CUploadedFile::getInstance($poster, 'image'); $poster->table = 'singer'; $poster->type_id = '3'; $poster->row_id = $row_id; if ($image_name = $poster->Add($new)) { echo CJSON::encode(array('part' => CHtml::image('/images/singer/' . $image_name, 'постер', array('class' => 'singer_poster_image', 'title' => "Постер Друга ріка")), 'status' => 'success', 'singer_id' => $row_id)); Yii::app()->end(); } else { echo CJSON::encode(array('part' => CHtml::textField('ERROR', ''), 'status' => $status)); Yii::app()->end(); } } if (Yii::app()->request->getPost('object') == 'style') { //редагуєм стилі $style_id = explode(',', Yii::app()->request->getPost('id')); $exist = Singer_style::model()->selectBySingerId($model->id); $parent = Style::model()->getNewParent($style_id, $exist); //error_log(var_export($parent,1)); if ($parent) { foreach ($parent as $key => $id) { if (!in_array($id, $style_id)) { $style_id[] = $id; } } } foreach ($style_id as $i => $id) { if (in_array($id, $exist)) { unset($style_id[$id]); continue; } $style[$i] = new Singer_style(); $style[$i]->singer_id = $model->id; $style[$i]->style_id = $id; } if (isset($style)) { $transaction = Yii::app()->db->beginTransaction(); try { foreach ($style as $i => $item) { $item->save(false); } $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); echo CJSON::encode(array('status' => 'error')); Yii::app()->end(); } } echo CJSON::encode(array('status' => 'success', 'singer_id' => $row_id)); Yii::app()->end(); } }