yii-cmodel

How to use model object in Yii Controller and View

荒凉一梦 提交于 2019-12-25 17:16:09
问题 I have following method: public function actionIndex() { $companyModel = Company::model()->findAll(); $supplierProductModel = SupplierProduct::model()->findAll(); $this->render('index', array( 'companyData' => $companyModel, 'supplierProductData' => $supplierProductModel, )); } Here I have passed model objects to render function and want to access these objects in view (Active Relational Type) but when I am accessing its in view its showing error: Trying to get property of non-object view

Yii Joined table but not all selected data is retrieved

不问归期 提交于 2019-12-23 22:12:46
问题 I have the following criteria in my controller. $criteria = new CDbCriteria; $criteria->select = 't.*,b.*,c.*'; $criteria->join = "INNER JOIN tbl_patient_chair b ON b.patient = '0005' INNER JOIN tbl_chair c ON b.chair = c.Serial_No"; $criteria->condition = "t.client_id = '0005'"; $model = Patient::model()->findAll($criteria); $this->render('view', array( 'model' => $model )); Then in my view I am trying to retrieve all the selected data by doing: foreach ($model as $models) print_r($model);

multi model forms in yii

倾然丶 夕夏残阳落幕 提交于 2019-12-17 22:34:31
问题 How to create a multi-model form in Yii? I searched the entire documentation of Yii, but got no interesting results. Can some one give me some direction or thoughts about that? Any help will be appreciable. 回答1: In my expirience i got this solution to work and quickly understandable You have two models for data you wish collect. Let's say Person and Vehicle . Step 1 : Set up controller for entering form In your controller create model objects: public function actionCreate() { $Person = new

Yii populate a dropdown on select of another

[亡魂溺海] 提交于 2019-12-13 05:07:41
问题 I have a dropdown that I want to populate when an item in another dropdown is selected. Both the dropdown are tied to data/model passed on from controller. and the first dropdown is populated from DB by calling a function in the model. Heres' the form, echo $form->dropDownListRow($modelunit, 'superunit', $model->getSunits(), array( 'ajax' => array( 'type'=>'POST', 'url'=>CController::createUrl('user/getunits'), 'update'=>'#unit_id', ))); echo CHtml::dropDownList('unit_id','', array()); Here's

ActiveRecord search returns 'Syntax error or access violation' error

懵懂的女人 提交于 2019-12-12 09:59:58
问题 In my Yii application, I have a model that represents siteconfig table and have four columns: integer config_id , string key , string value , string update_time . I created a model using Gii (to ensure that I will not make any mistakes). I don't publish entire code here, cause this is 100% unmodified by me, standard model code generated by Gii. Since my problem is related to search, I only publish important part of generated code (the search() method): public function search() { // Warning:

Yii CGrid pagination and sorting with CArrayDataProvider doesnt work

不打扰是莪最后的温柔 提交于 2019-12-09 13:01:48
问题 I built a custom function in my model and return the raw data: function(){ ... $connection=Yii::app()->db; $command=$connection->createCommand($sql); $rows=$command->queryAll(); return $rows; } $campModel = $model->function.. I then use those rows in CArrayDataProvider: $dataProvider=new CArrayDataProvider($campModel); Finally i'm trying to view using CGrid: $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'bo-campaigns-grid', 'dataProvider'=>$campModel,... I'm guessing this has to do

CModel vs CFormModel vs CActiveRecord

空扰寡人 提交于 2019-12-09 12:58:22
问题 I am building a db intensive application in yii . So performance and security are naturally a concern . Apart from that form validation is also a major criteria . For security I plan to use parameter binding for all Sql Queries . For validation I want to use validators provided by Yii instead of rolling out my own . I am aware that performance takes a hit with CActiveRecord . So I plan to make Cmodel classes for all my tables , define validation rules in these respective models and also

Yii Command Line Does Not Autoload Models

杀马特。学长 韩版系。学妹 提交于 2019-12-07 09:28:10
问题 I'm trying to run a command on the command line with Yii. My method requires a model but when I run the command, Yii says model does not exist, as if it is not auto-loading it. My class is fairly short and simple: class ImportCommand extends CConsoleCommand { public function actionIndex() { } public function actionImport() { ini_set("display_errors", 1); set_time_limit(0); $cores = Core::model() -> findAll(array('limit' => 300000)); foreach($cores as $core) { $core -> syncLocation(); } } }

ActiveRecord search returns 'Syntax error or access violation' error

ε祈祈猫儿з 提交于 2019-12-06 07:26:01
In my Yii application, I have a model that represents siteconfig table and have four columns: integer config_id , string key , string value , string update_time . I created a model using Gii (to ensure that I will not make any mistakes). I don't publish entire code here, cause this is 100% unmodified by me, standard model code generated by Gii. Since my problem is related to search, I only publish important part of generated code (the search() method): public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new

Yii Command Line Does Not Autoload Models

柔情痞子 提交于 2019-12-05 16:03:25
I'm trying to run a command on the command line with Yii. My method requires a model but when I run the command, Yii says model does not exist, as if it is not auto-loading it. My class is fairly short and simple: class ImportCommand extends CConsoleCommand { public function actionIndex() { } public function actionImport() { ini_set("display_errors", 1); set_time_limit(0); $cores = Core::model() -> findAll(array('limit' => 300000)); foreach($cores as $core) { $core -> syncLocation(); } } } The error message looks like this: ./yiic import import PHP Warning: PHP Startup: Unable to load dynamic