yii2

Yii2-Grid view showing wrong count of items

廉价感情. 提交于 2019-12-11 04:51:04
问题 I have grid view in which there are 8 items. But the count is displaying Showing 1-8 of 10 items. Controller code public function actionViewsetpdf($id) { $model = $this->findModel($id); $session = Yii::$app->session; $sqla = $session->get('result'); $session = Yii::$app->session; $cnt = $session->get('count'); $dataProvider = new SqlDataProvider([ 'sql' => $sqla, 'totalCount'=>$cnt, 'pagination' => [ 'pageSize' => 20, ], ]); return $this->render('viewsetpdf', [ 'dataProvider' => $dataProvider

Yii2 Paging with custom url rules

醉酒当歌 提交于 2019-12-11 04:50:49
问题 I'm trying to create paging in an application with the following custom rules 'enablePrettyUrl' => true, 'rules' => [ '/<id:\d+>' => 'news/view', '/<link>' => 'news/view', '/<technology>/<news>' => 'category/index', '/<technology>/<tags>/<title>' => 'category/tag', '<controller:\w+>/<action:\w+>/<id:\d+>' =>'<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>',] So how do I write the rule for paging which creates a url like this http://localhost/project/frontend

Returns the static model of the specified AR class in yii 2.0

╄→尐↘猪︶ㄣ 提交于 2019-12-11 04:49:09
问题 i want to build blog application using YII 2, i use the tbl_lookup table to store the mapping between integer values and textual representations that are needed by other data objects. i modify the Lookup model class as follows to more easily access the textual data in the table. here my code : <?php namespace common\models; use Yii; ?> class Lookup extends \yii\db\ActiveRecord { private static $_items=array(); public static function tableName() { return '{{%lookup}}'; } public static function

Yii2 rest: checkAccess on restAction

萝らか妹 提交于 2019-12-11 04:47:40
问题 After tackling this other question we would now like to check if the authenticated user can view, update or delete an existing record. Since checkAccess() is called by default in all restAction s the following seemed the most logic thing to try: public function checkAccess($action, $model = null, $params = []) { if(in_array($action, ['view', 'update', 'delete'])) { if(Yii::$app->user->identity->customer->id === null || $model->customer_id !== Yii::$app->user->identity->customer->id) { throw

How to disable sessions, cookies and auto login in Yii2?

末鹿安然 提交于 2019-12-11 04:46:02
问题 I am building stateless restfull API in Yii2. So I created new APP in my advanced app layout (as preferred by Yii2 creators) and configure all necessary things and API worked. Now I want to make it stateless - I want to disable session and I want it to be accomplished in config/main.php inside my API app to ensure it as global setting. Also I want to disable cookies and auto login. What I have been playing now so far is inside Module class <?php namespace api\modules\v1; use \app\models\User;

How to get a customer ID from event object in stripe

可紊 提交于 2019-12-11 04:42:47
问题 In my application, when a user signs up, a customer is created in stripe . A subscription is also created for that customer on trial basis. When that trial period ends, the customer is charged. I have a web-hook for events happening in stripe so whenever charge.succeeded occurs, I make some changes in my database. I need to retrieve the customer id form the event object that is posted from the stripe. and I am doing it like this: $stripeCustomerId = $event->customer; Now when I checked in

Retrieving image from postgresql database using Yii2 (php)

做~自己de王妃 提交于 2019-12-11 04:35:41
问题 We have a problem retrieving uploaded image from postgres database with yii2 we store image with that way to the db: $data = pg_escape_bytea(file_get_contents($model->CheckIfAvatarExists(Yii::$app->user->identity->username))); $profile->passphoto = new Expression("'{$data}'"); $profile->save(); stores image perfectly but when we try to display image, it is not working: header('Content-type: image/png'); echo pg_unescape_bytea( $profile->passphoto); I think the big problem is data after

Disable Yii Validation Error Message on focus / key up - Yii2

喜你入骨 提交于 2019-12-11 04:25:00
问题 As default, error message coming on keyup and after pressing submit button in form (If any error exist for that particular attribute). Which Is Ok. Working perfectly fine. But, Is it possible to disable error message on key up ? Means, error message, if any, should come only on pressing submit button. View <?php $form = ActiveForm::begin([ 'id' => 'register-form']); ?> <?= $form->field($model, 'first_name',['inputOptions' => ['class' => 'form-control fname','placeholder'=>'First Name']])-

Yii2. Access to higher level folder

廉价感情. 提交于 2019-12-11 04:19:45
问题 Simple question. I use Yii2 advanced template. In apache I have DocumentRoot "{$path}/www/yii-application1/frontend/web" . How can I access /www/yii-application1/uploads in order to show image to user? Following code does not work: <?php echo Html::img('../../uploads/ring.jpg') ?> It works with DocumentRoot "{$path}/www/yii-application1/" . But in this case an index page of website looks like domain.com/frontend/web . But I need just domain.com . 回答1: Step : 1 First create .htaccess file in

generate mysql query from relations using via or viaTable relations

时间秒杀一切 提交于 2019-12-11 04:18:34
问题 consider the below example... class Customers extends ActiveRecord { public function getOrders() { return $this->hasMany(Orders::className(), ['customer_id' => 'id']); } public function getOrderItems() { return $this->hasMany(OrderItems::className(), ['order_id' => 'id']) ->via('orders'); } } how i can generate any one of the follwing query from the getOrderItems() relation SELECT * FROM `order-items` LEFT JOIN `orders` ON `orders`.`id` = `order-items`.`order_id` LEFT JOIN `customers` ON