Yii

Clistview in yii Undefined variable dataProvider

青春壹個敷衍的年華 提交于 2019-12-20 06:22:44
问题 I need a list view in my index.php . This is does not have any model so I used CSqlDataProvider for declaring the data provider and rendering it to the index from the controller. Here is my controller action... public function actionIndex() { $sql="select * from Ads"; $totalItemCount=20; $dataProvider = new CSqlDataProvider($sql, array( 'totalItemCount' => $totalItemCount, )); $this->render('index',array('dataProvider'=>$dataProvider)); } Here is my index.php code.... $this->widget('zii

Updating and delete Related Models (Relational tables) in Yii

a 夏天 提交于 2019-12-20 06:08:52
问题 UPDATED I have two related models i.e. Candidate and Qualifications. They have one to one relationship between them. I am using CActiveForm and want to perform CRUD operation on the relational data. I had been able to insert the data but i am having issues with the update and delete. The function is displaying the $id but that the only thing that is displayed on the page. CandidateController public function actionUpdate($id) { echo $id;// this is printing the id on page $model = Candidate:

Trying to get property of non-object error in Yii

被刻印的时光 ゝ 提交于 2019-12-20 05:33:12
问题 Case 1: I get an array of CActiveRecords and try to loop over it as shown below: foreach ($pendingTasks as $task) { if($task->task->employee_id=="1") { //some logic here } } I get "Trying to get property of non-object " Case 2: If I try: $pendingTasks = TaskLog::model()->findByPk("1"); if($pendingTasks->task->employee_id=="1") { //some logic here } This works. Why is this so? Am I doing any thing wrong here? 回答1: Because of the tasks in $pendingTasks must not have a relation. You can check by

Exception nsresult: “0x805e0006 (<unknown>)” location when submitting changes using x-editable in yii

寵の児 提交于 2019-12-20 05:14:53
问题 I am getting the following exception when trying to ok the value in x-editable. [Exception... "" nsresult: "0x805e0006 ()" location: "JS frame :: :: .send :: line 8400" data: no] View Code: <?php $this->widget('bootstrap.widgets.TbGridView', array( 'id' => 'subjectgrid', 'itemsCssClass' => 'table-bordered items', 'dataProvider' => new CActiveDataProvider('Examschedule',array( 'criteria'=>array('condition'=>"examcode=:newexam and sessioncode=:sessioncode", 'params'=>array(':newexam'=>$examcode

Getting the string representation from CDbCriteria

醉酒当歌 提交于 2019-12-20 04:24:41
问题 Is there any way to the get the string representation of the query from CDbCriteria? For testing and debugging purposes. 回答1: You can use logging and profiling configuring your main.php like this: 'components'=>array( 'log'=>array( 'class'=>'CLogRouter', 'routes'=>array( array( 'class'=>'CWebLogRoute', 'categories'=>'system.db.CDbCommand', 'showInFireBug'=>true, ), ), ), 'db'=>array( 'enableProfiling'=>true, 'enableParamLogging'=>true, ), ), 回答2: I spend a lot amount of time for finding the

why pusher works on localhost but not on a live website

两盒软妹~` 提交于 2019-12-20 04:19:26
问题 I've used Pusher API to put a simple push notification in place. I've tested everything and Pusher works on my localhost . When I put the same code on a live website, Pusher doesn't publish my message. That's interesting to note that if I push from localhost I can see the message on the live version. It seems that I have no problem subscribing to a channel, but the problem is that I cannot publish a message on the channel. This is my code: // Create pusher event $pusher=Yii::app()->pusher;

Extract data from Relations

左心房为你撑大大i 提交于 2019-12-20 04:08:50
问题 I'm making an online shop. I have two models: Product and Category . Product can have one category, while category can have many products. I've defined relationships in models . I can access categories and products. But I want to get all products from specific category. I've tried many examples of relational queries with "lazy" and "eager" approach from official documentation, but no success. Can you please explain how to implement it? Here's my code: Category controller: public function

Extract data from Relations

落花浮王杯 提交于 2019-12-20 04:07:25
问题 I'm making an online shop. I have two models: Product and Category . Product can have one category, while category can have many products. I've defined relationships in models . I can access categories and products. But I want to get all products from specific category. I've tried many examples of relational queries with "lazy" and "eager" approach from official documentation, but no success. Can you please explain how to implement it? Here's my code: Category controller: public function

How to add span to a label using $form->labelEx from Yii?

喜欢而已 提交于 2019-12-20 04:05:13
问题 I wish to generate the following markup: <label>some label here <span>(optional)</span></label> Is there a way to do this, by using Yii labelEx or just label ? Thanks 回答1: If the attribute is required You can set the CHtml static properties like this CHtml::$beforeRequiredLabel = ''; CHtml::$afterRequiredLabel = '<span>(optional)</span>'; Yii will generate a tag <label>CHtml::$beforeRequiredLabel.$label.CHtml::$afterRequiredLabel</label> but the static properties will effect all labels

How to add span to a label using $form->labelEx from Yii?

点点圈 提交于 2019-12-20 04:05:10
问题 I wish to generate the following markup: <label>some label here <span>(optional)</span></label> Is there a way to do this, by using Yii labelEx or just label ? Thanks 回答1: If the attribute is required You can set the CHtml static properties like this CHtml::$beforeRequiredLabel = ''; CHtml::$afterRequiredLabel = '<span>(optional)</span>'; Yii will generate a tag <label>CHtml::$beforeRequiredLabel.$label.CHtml::$afterRequiredLabel</label> but the static properties will effect all labels