yii2

Add jquery in Yii 2.0

萝らか妹 提交于 2019-12-06 20:33:26
问题 How can i add jQuery to my page in Yii 2.0? In Yii 1.x you could just use: Yii::app()->clientScript->registerCoreScript('jquery'); I already tried to override the View class with my own and tried to register jQuery there, but it doesn't shows up in my html page: namespace frontend\components; /** * This is the base view object, it extends the yii\web\View so you can add custom view stuff here. */ class BaseView extends \yii\web\View { public function init() { parent::init(); \yii\web

How to create a Yii2 model without a database

℡╲_俬逩灬. 提交于 2019-12-06 20:26:07
问题 I would like to create a yii2 model without a database. Instead, the data is generated dynamically and not stored, just displayed to the user as a json. Basically, I would just like a get a simple, basic example of a non-database Model working but I can't find any documentation on it. So how would I write a model without a database? I have extended \yii\base\Model but I get the following error message: <?xml version="1.0" encoding="UTF-8"?> <response> <name>PHP Fatal Error</name> <message

Centos 6.8 下 Yii2 连接 MS SQL Server 2008(记录)

£可爱£侵袭症+ 提交于 2019-12-06 19:25:28
摸索这么久的原因,是拖得这么久。打开一个网页,发现很久以前就收藏过该网页了,却从来没有仔细看过。再次遇到问题,就花费了好多时间精力来搜索测试再搜索。发现就在曾经看过的网页里。本服务器是 64 位 centos 6.8。 参考网页: https://github.com/Microsoft/msphpsql/blob/PHP-7.0-Linux/LinuxTutorial.md https://blogs.msdn.microsoft.com/sqlnativeclient/2016/10/20/odbc-driver-13-0-for-linux-released/ https://www.microsoft.com/en-us/sql-server/developer-get-started/php-rhel 主要参考第一个网页。 一、安装 unixODBC 及 Microsoft ODBC driver for Linux 这个是参考另外一个 网页 的。内容基本一致,且本服务器是 centos 6.8 故摘抄如下: $ sudo su # curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo # exit $ sudo yum

In Yii2, how can I exclude layout from rendering in a view file?

∥☆過路亽.° 提交于 2019-12-06 19:06:29
问题 I have an admin login page that I want to render without the layout. How can I render a view in Yii2 without rendering the main layout? 回答1: This can be done using renderPartial() method. You can get more from the official documentation. Here's a link! 回答2: In your controller you can assing layout for all actions of controller or turn it off: class AdminController extends Controller { // public $layout='//admin'; public $layout=false; OR you can do it for only one action: public function

Yii2 - DetailView widget float left

和自甴很熟 提交于 2019-12-06 16:53:55
问题 I'm trying to override the disposal of the DetailView widget by applying new css class but with no luck. I want all the records shown in the several instances of a DetailView widget to appear side by side. I create a class in app\web\css called detail1-view and apply it to the detaiview.php in vendor folder. The class has float:left , or display:inline-block in it, but none of the attributes work. My Detailview is: <?= DetailView::widget([ 'model' => $model, 'attributes' => [ //'titulo',

Yii2 Activerecord get fields from junction table and order by according to them

*爱你&永不变心* 提交于 2019-12-06 16:13:47
I have items and units table that have many to many relationship. In other words, the item has many units and the unit has many items. I managed the relation through a junction table item_units . The junction table has some extra field more than item_id and unit_id , i.e it has price, and weight (it is an integer to manage the order of units for each item for display purposes). I managed the relations in the models as follows: //In Items model /** * @return \yii\db\ActiveQuery */ public function getItemUnits() { return $this->hasMany(ItemUnits::className(), ['item_id' => 'id'])->orderBy(['item

Yii2 get product id seperated by comma

北战南征 提交于 2019-12-06 15:54:07
问题 I have followed this guy tutorial and got total price of all products and now I have created a table called order which contains (total_price and product) columns now I want what all products ID which are selected (added to cart) separated by comma and be saved into $model= new orders () $model->product (product id added in cart separated by comma)in db I've saved total_price in db through controller though. Thanks in advance 回答1: Use PHP implode() and explode() function to save comma

How to set multi select value from array object in yii2 while updating

戏子无情 提交于 2019-12-06 14:18:49
I have table which have multiple reference to ohter tables like user id name email categories id title user_categories user_id category_id Here a user will have multiple category associated with him/her I am able to save these successfully with new records like following View File: echo $form->field($package_categories, 'category_id')->dropDownList( ArrayHelper::map( StudyMaterialCategories::find()->all(), 'id', 'title'), ['multiple' => true] ); Save New record: $model = new Packages(); $package_categories = new PackageCategories(); $request = Yii::$app->request; if ($request->isPost) {

Yii2 REST API BasicAuth not working

只愿长相守 提交于 2019-12-06 13:51:45
问题 Im implementing REST API Authentication module as following step 1. Create user by Admin 2. First tim: login by Basic Auth to return access_token 3. Use access_token at step 2 to Auth user by. QueryParamAuth as this instruction it work with QueryParamAuth https://github.com/yiisoft/yii2/blob/master/docs/guide/rest-authentication.md But it not work at step2. Auth by BasicAuth I debug it. $this->auth always return null. Although $username and $password right class HttpBasicAuth extends

Best practice for setting non-normalized columns in Yii2

ぐ巨炮叔叔 提交于 2019-12-06 13:35:22
Question to all Yii2 normalization geeks out there. Where is the best place to set non-normalized columns in Yii2? Example, I have models Customer , Branch , CashRegister , and Transaction . In a perfect world, and in a perfectly normalized Database, our Transaction model would have only the cashregister_id , The CashRegister would store branch_id , and the Branch would store customer_id . However due to performance issues, we find ourselves obliged sometimes though to have a non-normalized Transaction model containing the following: cashregister_id branch_id customer_id When creating a