yii2-advanced-app

Action not found after AJAX request

血红的双手。 提交于 2019-12-11 08:31:52
问题 Before for submitting I want to send the request to an action. But in return I get 404 not found . The action is obviously there. Also got it in the filters of the controller. JS: $('#home-contact').on('beforeSubmit', function(){ $.ajax({ method: 'post', url: '/site/send-contact', data: new FormData($(this))[0], success: function(data){ console.log(data) } }) return false }) Controller filters: 'access' => [ 'class' => AccessControl::className(), 'only' => ['logout', 'signup', 'send-contact']

Yii2 hasOne relation link to multiple table

走远了吗. 提交于 2019-12-11 08:03:55
问题 I have 4 tables are agent, vendor, operator and ticket. A ticket is belong to only one of agent, vendor or operator. I designed ticket table have two fields: org_type and org_id In Ticket model class, I want to build 3 function getAgent, getVendor, getOperator use hasOne relation of Yii2 Solution 1: public function getAgent() { if ($this->org != Organization::ORGANIZATION_TYPE__AGENT) return null; return $this->hasOne(Agent::class, ['id' => 'org_id']); } will be failed because I can't use

Assigning function to value attribute in details view yii2 [duplicate]

六眼飞鱼酱① 提交于 2019-12-11 06:49:44
问题 This question already has answers here : Changing value of an attribute in DetailView widget (2 answers) Closed 3 years ago . I am trying to assign a value of a function to 'value' in DetailView. But when I try that I get the error "Object of class Closure could not be converted to string" I tried returning the value of the function by assigning it to another variable too but still the same error. Can someone help me figure it out please? <?= DetailView::widget([ 'model' => $model,

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;

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

Yii2 - Bad Request (#400) | Frontend and backend cookies

折月煮酒 提交于 2019-12-11 02:13:56
问题 The issue appears only when I open frontend and backend in the same browser . Scenario: Interact with Backend -> Switched Tab -> Interact with Frontend -> Switched Tab Back -> Interact with Backend -> Bad Request (#400) Cookie Backend 'identityCookie' => [ 'name' => '_backendIdentity', 'path'=>'/admin', 'httpOnly' => true, ], Cookie Frontend 'identityCookie' => [ 'name' => '_frontendIdentity', 'path'=>'/', 'httpOnly' => true, ], Session Backend 'session' => [ 'name' => 'session_backend' ],

Yii2- How to search gridview records using kartik date time picker

纵饮孤独 提交于 2019-12-11 01:17:39
问题 I am working in yii2 framework. I have two kartik date time pickers in my index view. I want to use them to search the records. <section class="content"> <div class="box"> <div class="box-body"> <p> <?= Html::a('Update Record', ['create'], ['class' => 'btn btn-success']) ?> </p> <div class="div1" style="float: left; text-align: right; width: 25%;"> <span style="padding-bottom: 10px; border-bottom: 1px solid black"> <?php echo DateTimePicker::widget([ 'name' => 'startTime', 'options' => [

appendTimestamp and registerAssetBundle

一曲冷凌霜 提交于 2019-12-11 01:12:34
问题 I am using the following configurations to add the timestamp in the assets path via asset manager. 'assetManager' => [ 'appendTimestamp' => true, appAsset.php class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ '/css/style.css' ]; } In view AppAsset::register($this); But in html I still see '/css/style.css' without timestamp. I saw solution https://github.com/yiisoft/yii2/issues/9101#issuecomment-267274327 $file = '/css/style.css';

How to display selected values in multiple select dropdown in a Yii2 app?

放肆的年华 提交于 2019-12-10 21:05:38
问题 I am working on Yii2. I am creating multiple select drop down using custom array like this. In controller file: $all_groups = Groups::find()->where(['=','group_created_by',$id])->orwhere(new Expression('FIND_IN_SET(:id_to_find, group_managers)'))->addParams([':id_to_find' => $id])->all(); // fetch all values $selected_groups = Groups::find()->where(['=','group_users',$updateId])->orwhere(new Expression('FIND_IN_SET(:id_to_find, group_users)'))->addParams([':id_to_find' => $updateId])->all();