Yii

Yii: using active record with autocommit off on mysql server

自作多情 提交于 2019-12-24 12:54:50
问题 Just wrote a Yii app and on the development mysql server the autocommit was set to true. Now when the app went into production I just realized that the mysql server autocommit is set to false. The app is using active record to save (which auto commits). Is there a variable that I can set in the config db file instead of having to add a beginTransaction and commit in each write to the db? 回答1: CDbConnection has an autoCommit property. I haven't tested it yet though. EDIT because of PHP MySQL

URL rewriting with Yii framework

坚强是说给别人听的谎言 提交于 2019-12-24 12:36:34
问题 I have a url like www.example.com/food/xyz for which I have written a rule like this in the main.php (config folder) 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'caseSensitive'=>false, 'rules'=>array( '/food/<name:\w+>/' => 'food/index/', '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ), This means that internally "xyz" will be passed as a

Yii model findAll() and count() return different number of results

笑着哭i 提交于 2019-12-24 12:33:54
问题 UPDATED: see the end of the question I'm working with Yii (and RESTFullYii in particular but I doubt that is relevant to the question) There is a CDbCriteria for a model: $criteria = new CDbCriteria( array( 'together' => true, 'with' => array( 'roles'=> array( 'having' => "roles.role IN ($userRoles)" )) ) ); $count = $model->count($criteria); $result= $model->findAll($criteria); While the findAll() method returns only 3 records (which is good) the count() method returns 13 which is the total

Running PHPUnit tests Yii Framework

放肆的年华 提交于 2019-12-24 12:13:29
问题 What possibilities are there to run unit tests with my Yii application? So far, I have been testing them this way: Open command prompt > cd C:\WHEREVER MY APP IS\protected\tests > phpunit unit/TestingTest.php Now, I was wondering if there is another way. Im new to the testing world so to speak, but it seems to me that there must be a better way than running one by one all tests. Thanks for any tips, im sure the question is quite dumb! But maybe it turns out to be helpful to someone else out

Convert ajax response array object to javascript array?

扶醉桌前 提交于 2019-12-24 11:35:06
问题 I am using ajax to submit a login form in Yii. Here is my ajax function: $("#login-form").submit(function() { var email = $("#email").val(); var password = $("#password").val(); $.ajax({ url: "<?php echo Yii::app()->request->baseUrl; ?>/site/validatelogin", type: "post", data: "email=" + email + "&password=" + password, success: function(response) { if (response === "1") { window.location.href = "<?php echo Yii::app()->getBaseUrl(true); ?>/dashboard"; } else { //Dispaly response errors above

File upload with Yii's ActiveForm

半城伤御伤魂 提交于 2019-12-24 09:27:24
问题 I am trying to use Yii's ActiveForm to create a basic registration page with an image upload field. However, I am running into problems. I am using the following code to create the form tags: $form=$this->beginWidget('CActiveForm', array( 'id'=>'activity_form', 'enableAjaxValidation'=>true, 'stateful'=>true, 'enctype'=>'multipart/form-data' )); The above code produces the following error message in Yii: Property "CActiveForm.enctype" is not defined I've also tried: $form=$this->beginWidget(

Changing sql query to yii2 format

僤鯓⒐⒋嵵緔 提交于 2019-12-24 07:13:03
问题 Am using dataProvider and i would like to convert a query in sql so that it follows the dataProvider way of representing data This is the raw sql SELECT tblpritems.PRlineID , tblpritems.Tracking_Code , tblpritems.Description , tblpritems.Quantity , tblpritems.Unit_Price , tblpritems.Extended_price , tblpritems.PRID , tblpritems.pr_solicitation_id , tblpritems.date_item_received , tblpritems.Quantity_received , tblpritems.Remarks_on_receipt , tblpritems.Received_by FROM prts.tblpritems INNER

Yii Localisation - CDbMessageSource example

拈花ヽ惹草 提交于 2019-12-24 06:49:54
问题 I'm newbie to Yii. Official documentation does not give any examples for CDbMessageSource. Questions: 1) How/Where do I set CDbMessageSource as my MessageSource ? 2) In my current application I store Categories in one table and translations for Categories in other table. Tables structure: CATEGORY ---------- cat_id (PK) CATEGORY_TRANSLATION -------------------- cat_id (FK) en ru Now if I introduce sub-categories I would model DB this way: SUB_CATEGORY ------------ sub_cat_id (PK) cat_id (FK)

Insert data in two different tables from single Controller in Yii

不羁岁月 提交于 2019-12-24 05:54:43
问题 I have two different table and i want to insert data in both of them at a time. ONE table is verse verse(id, topic_id, surah_id, verse_text) // id is primary key, Second table is verse_translations verse_translations(id, verse_id, language_id, translations_text) // id is primary key, language_id is foreign key references with language table, // verse_id is foreign key references with verse table. Verse Create File (_form.php) <div class="form"> <?php $form = $this->beginWidget('CActiveForm',

Insert data in two different tables from single Controller in Yii

时光怂恿深爱的人放手 提交于 2019-12-24 05:54:03
问题 I have two different table and i want to insert data in both of them at a time. ONE table is verse verse(id, topic_id, surah_id, verse_text) // id is primary key, Second table is verse_translations verse_translations(id, verse_id, language_id, translations_text) // id is primary key, language_id is foreign key references with language table, // verse_id is foreign key references with verse table. Verse Create File (_form.php) <div class="form"> <?php $form = $this->beginWidget('CActiveForm',