yii2

Complex Database Queries in yii2 with Active Record

℡╲_俬逩灬. 提交于 2019-12-22 09:15:15
问题 TL;DR I have a query that works in RAW SQL but i have had little success recreating it with query builder or active record. I am working on a web application based off of the yii2 advanced application template. I have written a database query and implemented it with findbysql() returning the correct records but am having trouble translating this into active record. I originally wanted to allow the user to modify (filter) the results by means of a search form(user & date), however i have since

Yii2 Invalid Call: Setting read-only property

混江龙づ霸主 提交于 2019-12-22 09:04:23
问题 I have a Post model that has a many-many relationship with Tags . Defined in Post model: public function getTags(){ return $this->hasMany(Tags::className(), ['id' => 'tag_id']) ->viaTable('post_tags', ['post_id' => 'id']); } But Post::tags is read-only. So when I try to set them in the Controller, I get an error: Invalid Call – yii\base\InvalidCallException Setting read-only property: app\models\Post::tags The controller is using load to set all the properties: public function actionCreate(){

Yii2 Username and password encryption

限于喜欢 提交于 2019-12-22 08:57:43
问题 I had scanned my yii2 application few days before and noted that username and passwords from the login form is posting without any encryption. How can i make my username and password more secure?I know \yii\helpers\Security::encrypt($data, $secretKey) will encrypt the data and similiary we can decrypt it. But how to use it in a view like login form? This is my login form <?php $form = ActiveForm::begin(['id' => 'login-form']); ?> <?= $form->field($model, 'username') ?> <?= $form->field($model

Prevent multiple clicks and ActiveForm submission in Yii 2.0.10

余生长醉 提交于 2019-12-22 08:26:19
问题 I use ActiveForms often and find it handy as it includes client-side validation scripts yii.js and yii.activeForm.js . It normally takes care of model rules and basic validation on its own. Until Yii 2.0.9: We could use following script to prevent multiple form submission due to rapid button clicks: $('form').submit(function(){ $(this).find('button[type!="button"],input[type="submit"]').attr("disabled",true); setTimeout(function(){ $('form .has-error').each(function(index, element) { $(this)

Yii2 - Table alias with ActiveRecord

耗尽温柔 提交于 2019-12-22 05:40:32
问题 I have a table with a long name, example products_with_a_long_name . The Model name is ProductsWithALongName . Now, I have a query where I need to select many columns from this table while joining with another table. Example: ProductsWithALongName::find() ->select(['products_with_a_long_name.id', 'products_with_a_long_name.selling_price','client.name']) ->leftjoin('all_the_clients as client','products_with_a_long_name.clientId = client.id') ->where(['products_with_a_long_name.id' => $var]);

Submitting Button Value to Controller but fail to post the value

杀马特。学长 韩版系。学妹 提交于 2019-12-22 05:38:41
问题 I know i have made mistakes here but i have been searching for this for the whole day. I used yii2 framework and i am still new here, I want to access partone/two page, the partone/two page has two submit buttons, one is for adding row, the second one is for validating the input inside PartoneController.php <? public function actionTwo() { if(\Yii::$app->user->isGuest) { $this->goHome(); } $models = []; $val = "" ; //Create array of items Yii::trace("Lets start: "); if(Yii::$app->request-

Updating Image in Yii2

随声附和 提交于 2019-12-22 05:14:10
问题 While updating image using Yii2 I'm facing a problem with the validation.Its always asking me to upload an image. But I don't want this. Always updating an image is not necessary. I tried skipOnEmpty but its not working properly it cause effect while uploading a photo, which is also incorrect. Please help!! Model public function rules() { return [ [['carid', 'name'], 'required'], [['carid', 'coverphoto', 'status'], 'integer'], [['name'], 'string', 'max' => 200], [['imageFiles'], 'image',

Updating Image in Yii2

亡梦爱人 提交于 2019-12-22 05:14:05
问题 While updating image using Yii2 I'm facing a problem with the validation.Its always asking me to upload an image. But I don't want this. Always updating an image is not necessary. I tried skipOnEmpty but its not working properly it cause effect while uploading a photo, which is also incorrect. Please help!! Model public function rules() { return [ [['carid', 'name'], 'required'], [['carid', 'coverphoto', 'status'], 'integer'], [['name'], 'string', 'max' => 200], [['imageFiles'], 'image',

Yii2 Rest - Custom action and OPTIONS method

对着背影说爱祢 提交于 2019-12-22 04:35:36
问题 I'm having trouble with the following action "/login" route action in my UsersController class public function actionLogin(){ $data = Yii::$app->getRequest()->getBodyParams(); $model = new Usuario(); //Validamos que se hayan recibido los campos if(empty($data['email']) || empty($data['password'])){ throw new \yii\web\BadRequestHttpException("Debe ingresar email y password"); } //Validamos usuario y contraseña $usuario = $model->findByUsername($data['email']); if(empty($usuario) || !$usuario-

Can you run console jobs from yii2-basic?

▼魔方 西西 提交于 2019-12-22 04:33:09
问题 I am aware that Yii2-advanced has the ability to run console jobs (php yii controllername) but I was wondering if the basic app has the same ability? I notice a console.php file in the config folder, but cannot seem to get the jobs to run. If it is possible, can someone give an example - where does the controller go (since I put it in controllers, but I get the message 'Error: Unknown command test' when trying php yii test) Any help appreciated. 回答1: Yes, the same functionality exists in the