Yii

Yii framework async request

你离开我真会死。 提交于 2019-12-19 11:21:16
问题 I have ajax request that do 3 missions: Save Model (DB) Send Email Give success or failed message. Because this mission takes too time. User can wait up to 20 sec for response (success or failed message). And if the user close the browser its stop in one of the operation that current process for the user. This is bad user experience. I want user submit his data to my Controller and after it he will get the "success or failed message". And the process will be completely in the server side and

does gii automatically create relations for generated models?

牧云@^-^@ 提交于 2019-12-19 10:44:20
问题 I'm new to Yii here. In the documentation, it seems to imply that gii will create the relations for related models. But when using gii to generate models from DB, it doesn't seem to be the case. For example, I have a user table and a profile table with a column "user_id INTEGER DEFAULT 0", but the relations array is empty in the generated model. Did I do something wrong, or gii just doesn't automatically recognize the relations? Thanks, 回答1: Gii will create relations for MyISAM tables if you

浅析Yii2中GridView常见操作

梦想的初衷 提交于 2019-12-19 10:40:11
本文是小编给大家收集整理些有关网络上GridView出现的大部分问题,本文做一个总结特此分享到脚本之家平台供大家参考。 如果下面有没说到的GridView常见问题,下方留言,我会进行补充。 下拉搜索 日期格式化并实现日期可搜索 根据参数进行是否显示 链接可点击跳转 显示图片 html渲染 自定义按钮 设定宽度等样式 自定义字段 自定义行样式 增加按钮调用js操作 yii2 GridView 下拉搜索实现案例教程 yii2 GridView 日期格式化并实现日期可搜索 案例 是否显示某列案例 我们举一个简单的案例 条件:有一个get形参数type 需求:仅且type的值等于1的时候,列name才显示,否则该列不显示 代码实现如下: [ 'attribute' => 'name', 'value' => $model->name, 'visible' => intval(Yii::$app->request->get('type')) == 1, ], 实现方式也是很简单滴。 链接可点击跳转案例 这个跟接下来我们要说的html渲染的效果十分类似,这里要说的是列的属性值 format,具体都有哪些格式可查看文件 yii\i18n\Formatter.php,各种format都可以解决 [ 'attribute' => 'order_id', 'value' => function (

cascade delete the child record of the table

随声附和 提交于 2019-12-19 09:22:07
问题 I have table with column id, name and parentid relation function in model: 'location_parent' => array(self::BELONGS_TO, 'Location', 'parentid'), 'location_children' => array(self::HAS_MANY, 'Location', 'parentid', 'order' => 'id ASC'), delete action in controller: public function actionDelete($id) { $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if(!isset($_GET['ajax'])) $this->redirect(isset($_POST[

Yii CMultiFileUpload select multiple files

做~自己de王妃 提交于 2019-12-19 08:55:14
问题 Got The Answer To upload multiple file in to the database for registration have tried so many ways to make multiple file upload workable using CMultiFileUpload widget. Already, I have checked and followed below links- http://www.yiiframework.com/forum/index.php/topic/47665-multiple-file-upload/ Yii multiple file upload BUT still no luck!! Error: storing the data but the files are not getting uploaded please help Here is my code: In Form <?php $this->widget('CMultiFileUpload', array( 'model'=>

Php rewrite url through .htaccess

偶尔善良 提交于 2019-12-19 07:46:09
问题 I want to rewrite some url by using .htaccess rewrite I have url something like this: domain.com/app/index.php/appmedia/default/login and want to rewrite users to domain.com/app/index.php/zurmo/default/login So, what will happen is users will see appmedia in browser but in the backend it will access zurmo I'm new to php and have read some blogs like this have no luck Also, have tried this RewriteEngine On RewriteRule ^app/index.php/appmedia/default/login.*$ http://domain.com/app/index.php

How do I use the ajaxUrl parameter of CGridView in Yii?

狂风中的少年 提交于 2019-12-19 07:28:08
问题 I'm trying to use ajaxUrl param of CGridView and it's having no effect. $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'ge-cg-'.$myLib['id'], 'filter'=>$geCGModel, 'dataProvider'=>$dataProvider, 'columns'=>$columns, 'ajaxUrl'=>Yii::app()->createUrl( 'Something/search' ), )); This doesn't seem to be overriding the ajax url of the CGridView widget. The grid's ajax request is still going to the controller that rendered it (which is different than the grid's own controller). Thanks! 回答1

Get the absolute row number in a grid

让人想犯罪 __ 提交于 2019-12-19 05:53:05
问题 In yii's CGridView I can get the current row number by using $row . But this returns the row index within the current page only. What I really need is to get the absolute row number among all pages. I am using yii, so my dreams should come true "easily", so I expect the answer should not guide me to add a special field to the data provider or access the pager and get the current page number and then multiply numbers bla bla bla. Thanks 回答1: Have you solved this? If not, I offer you the

Yii , show different date format in cgridview

故事扮演 提交于 2019-12-19 05:16:10
问题 I had following cgridview in Yii application, I want to change date format in value, 'columns'=>array( array( 'name'=>'Date', 'header'=>'Date', 'value'=>'$data["work_date"]' ), I want to show date in format dd-mm-yyyy currently it shows as yyyy-mm-dd. 回答1: Try this, array( 'name'=>'Date', 'header'=>'Date', //'value'=>'date("d M Y",strtotime($data["work_date"]))' 'value'=>'Yii::app()->dateFormatter->format("d MMM y",strtotime($data->date))' ), 回答2: I guess there is more elegant way to format

How do I pass a global variable in Main layout page before $content in Yii2

谁说我不能喝 提交于 2019-12-19 04:14:07
问题 I am trying to create dynamic menu in yii2 using "Nav::widget". Here is my code in menu section in main layout page: echo Nav::widget([ 'options' => ['class' => 'navbar-nav navbar-right'], 'items' => [ ['label' => 'Home', 'url' => ['/site/index']], ['label' => 'About', 'url' => ['/site/about']], Trying to get the solution: Please have a look:: 1 I have created a super controller "components/Controller.php" in app: namespace app\components; use app\models\MenuPanal; class Controller extends