yii2

Ajax form submitting twice with Yii 2

こ雲淡風輕ζ 提交于 2019-12-10 14:19:45
问题 I've looked around and none of the other similar posts have helped me. I have built an AJAx based form in Yii 2 and jQuery and it seems it submits the form twice. My form: $form = ActiveForm::begin([ 'id' => 'company_form', 'ajaxDataType' => 'json', 'ajaxParam' => 'ajax', 'enableClientValidation' => false ]); My JS code: $(document).ready(function() { /* Processes the company signup request */ $('#company_form').submit(function() { signup('company'); return false; }); }) function signup(type)

Yii2 - insert relational data with junction table, many-many connection

那年仲夏 提交于 2019-12-10 14:08:39
问题 I have a problem with Yii2 (Stable). I have a Content(PK:id) table, I have a Tag(PK:id) table, and I have a junction table called Content_Tag (PK:content_id, tag_id). I'd like to use it for tagging, like WP tags. All controllers and models are created with gii. I have two problems: If I create a new content, I'd like to save some new tags to the Tag table via the Content_Tag table. How can I do that? With link()? What if there are tags (I know the ids) in the tag table, I'd like to connect

How to format currency sign in Yii2 after the value?

一曲冷凌霜 提交于 2019-12-10 13:48:10
问题 Right now when I have defined the currencyCode, the currency sign appears in front of the value like €10 000,00, but I'd like to have it like 10 000,00€. How to do that? At the moment I'm printing '€' separately after the value, but I'm just wondering if there's any way to automate the process. 回答1: I was able to resolve this issue installing php5-intl and using this way Yii::$app->formatter->locale = 'et-EE'; echo Yii::$app->formatter->asCurrency(1202.57, 'EUR'); It will change the sign

How to refresh pjax listview in yii2? It reloads the entire page

自作多情 提交于 2019-12-10 13:46:37
问题 I want to be able to refresh a pjax listview without refreshing the whole page. This is the view just the pjax list itself. <?= Html::Button('refresh-countries', ['class' => 'btn btn-primary', 'name' => 'login-button', 'id'=>'refresh']) ?> <?php Pjax::begin(['id' => 'countries']) ?> <?= ListView::widget([ 'dataProvider' => $dataProvider, 'itemOptions' => ['class' => 'comment-item'], 'itemView' => 'commentadapter', ]); ?> <?php Pjax::end() ?> Please I want it to refresh onclick of that button

Yii2 How to pass the model instance to the main layout?

喜夏-厌秋 提交于 2019-12-10 13:40:00
问题 I have a change password bootstrap modal which will get triggered when the user clicks on the Change password navBar menu. I have included the modal in the footer. But how can I pass the ChangePassword model instance to the footer layout file? Can beforeRender Or EVENT_BEFORE_RENDER be used? If yes, How? As suggested, I have put the following code in common/config/bootstrap.php: yii\base\Event::on(yii\base\View::className(), yii\base\View::EVENT_BEFORE_RENDER, function() {

What's the difference between init() and __construct() methods in Yii2

与世无争的帅哥 提交于 2019-12-10 13:39:10
问题 init() method : public function init() { } __construct() method: public function __construct() { } So, what's the differentce between them, and which should be used? 回答1: init() is the method of any object that extends from yii\base\Object (and the majority of objects extends from it). From official docs: Besides the property feature, Object also introduces an important object initialization life cycle. In particular, creating a new instance of Object or its derived class will involve the

Yii2 multiple models in one form

孤者浪人 提交于 2019-12-10 13:28:17
问题 How to use multiple models in one form in Yii2? My case: In my create action I can save into agenda_fiscalizacao table, but in update I receive this error when I try to load the form: Call to a member function formName() on array My Update Action: public function actionUpdate($id) { $model = $this->findModel($id); $modelAgenda = AgendaFiscalizacao::findAll(['fiscalizacao_id' => $id]); if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($modelAgenda, Yii::$app->request->post())

Yii2 step-by-step guide on login from table in MySQL

主宰稳场 提交于 2019-12-10 13:26:46
问题 I'm begining to make the first steps in Yii2. So far, I was able to write an application and connect a table in a database to it, just like I learned to do in Yii1. The table is contacts and the form in my create view sends the data to the database with no problems. The problem is that I only can login using Admin/Admin or demo/demo in the static user model that comes built-in in Yii2. In Yii1.xx i manage to validate login from a table in database using COMPONENTS/useridentity, just like this

How to configure global uploadPath and uploadUrl in Yii2?

倾然丶 夕夏残阳落幕 提交于 2019-12-10 13:23:35
问题 I want to configure Global Params in Yii2. For example this: This will store the server path for all your file uploads. Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/uploads/'; This will store the Url pointing to server location for your file uploads. Yii::$app->params['uploadUrl'] = Yii::$app->urlManager->baseUrl . '/uploads/'; When I set params like this: 'uploadPath' => Yii::$app->basePath . '/uploads/', 'uploadUrl' => Yii::$app->urlManager->baseUrl . '/uploads/', I am getting

How to put custom HTML into Yii2 GridView header?

孤者浪人 提交于 2019-12-10 13:19:22
问题 There's this <abbr></abbr> tag in bootstrap that will automatically shows popup of the abbreviated word. I want to insert this tag to a certain header in the gridview with attribute name act . Here is my code so far. [ 'attribute'=>'act', 'format'=>'raw', 'label'=>'<abbr title="Area Coordinating Team">ACT</abbr>', 'value'=>function($model){ return '<span class="fa fa-thumbs-up text-green"></span>'; } ], but the output literally shows the whole <abbr title="Area Coordinating Team">ACT</abbr>