Advertisement
Guest User

Untitled

a guest
May 14th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. <?php
  2. namespace appmodels;
  3.  
  4. use yiidbActiveRecord;
  5. use yiiwebIdentityInterface;
  6. use yiiwebUploadedFile;
  7. class User extends ActiveRecord implements IdentityInterface{
  8. public $file;
  9.  
  10. public function rules()
  11. {
  12. return [
  13. [['file'], 'file']
  14. ];
  15. }
  16.  
  17. public function setPassword($password){
  18. $this->password=sha1($password);
  19. }
  20.  
  21. public function validatePassword($password){
  22. return $this->password === sha1($password);
  23. }
  24.  
  25. public function attributeLabels()
  26. {
  27. return [
  28. 'file'=>'Main photo',
  29. ];
  30. }
  31.  
  32. public function fileInsert(){
  33. $this->file=UploadedFile::getInstance($this,'file');
  34. $this->file->saveAs('img/avs/'.$this->id.'/'.$this->file->baseName.'.'.$this->file->extension);
  35. $this->img='img/avs/'.$this->id.'/'.$this->file->baseName.'.'.$this->file->extension;
  36. return $this->img;
  37. }
  38.  
  39. public static function findIdentity($id)
  40. {
  41. return self::findOne($id);
  42. }
  43.  
  44. public static function findIdentityByAccessToken($token, $type = null)
  45. {
  46. // TODO: Implement findIdentityByAccessToken() method.
  47. }
  48.  
  49. public function getId()
  50. {
  51. return $this->id;
  52. }
  53.  
  54. public function getAuthKey()
  55. {
  56. // TODO: Implement getAuthKey() method.
  57. }
  58.  
  59. public function validateAuthKey($authKey)
  60. {
  61. // TODO: Implement validateAuthKey() method.
  62. }
  63. }
  64.  
  65. <?php
  66.  
  67. namespace appmodulesUsercontrollers;
  68.  
  69. use appmodelsPosts;
  70. use yiiwebController;
  71. use yiiwebUploadedFile;
  72. use yiiwebUser;
  73. use Yii;
  74. use appmodelsInfo;
  75.  
  76. class InfoController extends Controller{
  77. public $layout = '/info/main';
  78.  
  79. public function resize($file_input, $file_output, $w_o, $h_o, $percent = false) {
  80. list($w_i, $h_i, $type) = getimagesize($file_input);
  81. if (!$w_i || !$h_i) {
  82. echo 'Невозможно получить длину и ширину изображения при уменьшении';
  83. return;
  84. }
  85. $types = array('','gif','jpeg','png');
  86. $ext = $types[$type];
  87. if ($ext) {
  88. $func = 'imagecreatefrom'.$ext;
  89. $img = $func($file_input);
  90. } else {
  91. echo 'Некорректный формат файла';
  92. return;
  93. }
  94. if ($percent) {
  95. $w_o *= $w_i / 100;
  96. $h_o *= $h_i / 100;
  97. }
  98. if (!$h_o) $h_o = $w_o/($w_i/$h_i);
  99. if (!$w_o) $w_o = $h_o/($h_i/$w_i);
  100. $img_o = imagecreatetruecolor($w_o, $h_o);
  101. imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
  102. if ($type == 2) {
  103. return imagejpeg($img_o,$file_output,100);
  104. } else {
  105. $func = 'image'.$ext;
  106. return $func($img_o,$file_output);
  107. }
  108. }
  109.  
  110. public function actionIndex()
  111. {
  112. $id=Yii::$app->user->identity->id;
  113. $user = appmodelsUser::findOne(['id' => Yii::$app->user->identity->id]);
  114. if(Yii::$app->request->post('User')){
  115. $user->name=$_POST['User']['name'];
  116. $user->surname=$_POST['User']['surname'];
  117. $d=strtotime($_POST['User']['date']);
  118. $user->date=date("Y-m-d", $d);
  119. $user->country=$_POST['User']['country'];
  120. $user->city=$_POST['User']['city'];
  121. $user->about=$_POST['User']['about'];
  122. $user->fileInsert();
  123. echo "Loaded";die();
  124. if($user->validate()){
  125. $user->save();
  126. echo "success";
  127. }
  128. }
  129. return $this->render('info', ['user' => $user]);
  130. }
  131. }
  132.  
  133. <?php
  134. namespace yiijui;
  135. use yiiwidgetsActiveForm;
  136. use yiijuiAutoComplete;
  137. use zxbodyayii2tinymceTinyMce;
  138. use yiiwebUploadedFile;
  139. ?>
  140.  
  141. <?php
  142. $form = ActiveForm::begin(['class'=>'form-horizontal']);?>
  143. <?= $form->field($user,'file')->fileInput();?>
  144. <?= $form->field($user,'name')->textInput();?>
  145. <?= $form->field($user,'surname')->textInput();?>
  146.  
  147. <?= $form->field($user,'date')->widget(DatePicker::className()) ?>
  148. <?= $form->field($user, 'country')->widget(yiijuiAutoComplete::classname(), [
  149. 'clientOptions' => [
  150. 'source' => ['USA', 'RUS','UA'],
  151. ],
  152. ]) ?>
  153. <?= $form->field($user, 'city')->widget(yiijuiAutoComplete::classname(), [
  154. 'clientOptions' => [
  155. 'source' => ['Kyjv', 'Moskov','Khmelnitsky'],
  156. ],
  157. ]) ?>
  158. <?=$form->field($user, 'about')->widget(
  159. TinyMce::className(),
  160. ['spellcheckerUrl'=>'http://speller.yandex.net/services/tinyspell']
  161. ) ?>
  162.  
  163. <button type="submit" class="btn btn-primary">save</button>
  164. <?php
  165. ActiveForm::end();
  166. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement