Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

  • Days Won


lrzins last won the day on August 8 2017

lrzins had the most liked content!

Community Reputation

1 Neutral

About lrzins

  • Rank
  1. Hi Larry, on page 216 of your Yii book, you describe how to rename an uploaded file using the $model->id of the User model. I think this is a good idea, but I don't see how your code can work without an afterSave or something. Here is your code: $model->avatar->saveAs($dest . '/' . $model->id . '.' . $model->avatar->extensionName); The line above would have to come after the code to save the model: if ($model->save()) because you don't obtain the $model->id until after you save it. But since you've already saved the file's name to the database, the filen
  2. Hi Larry, to determine if any records are returned using find() and findAll(), I see that when nothing is returned using find(), that a NULL is returned. When nothing is found using findAll that an empty array is returned. Is this the best way to determine if records are returned?: $var=SomeModelClass::model()->find($condition, $params); if ($var !== null) // Check if a single record is returned. $var=SomeModelClass::model()->findAll($condition, $params); if (!empty($var)) // Check for returned records Larry Z.
  3. Wow!!!!! I got it working!!!! Iiiiieeeeeeeeyyyaaaaa!!! I just had to change the 'desc' value (above) to this: 'desc'=>'department.department_abbreviation desc, course_number desc', and now it finally sorts with two related fields. Happy happy Larry Z.
  4. Update: To sort by department abbreviation + course number, I had to use this in the Course model: public function search() { $criteria=new CDbCriteria; $criteria->with = array('department'); $criteria->compare('department.department_abbreviation',$this->dept_course,true); // Other criteria return new CActiveDataProvider($this, array( 'criteria'=>$criteria, 'sort'=>array( 'attributes'=>array(
  5. Hi Larry, I got the column to sort. I'm fairly comfortable with the solution, but still wonder if there is a better way. I'll definitely revisit this later. Here's what I did: Created a new attribute called $dept_course in my Model: class Course extends CActiveRecord { public $dept_course; Then set up the search() method in the Course Model to use this attribute to access the related fields in the Department Model, and sort the returned values: public function search() { $criteria=new CDbCriteria; $criteria->with = array('department
  6. Well in fact that column is defined as: array('name'=>'Course', 'value'=>'CValidator::isEmpty($data->course) ? "Other University" : $data->course->department->department_abbreviation . " " . $data->course->course_number'), but now it's not sortable when clicking the column header. I can't figure out how to sort this column. Is it easy? Larry Z.
  7. Hey this works: array('name'=>'Course', 'value'=>'CValidator::isEmpty($data->course) ? " " : $data->course->course_number'), Yay! Larry Z.
  8. I found the cause of the problem. It's that I need to have a NULL value in a foreign key. I have the foreign key "course_id" defined in a course_taken table, that references the course table, that needs to be NULL sometimes. In the CGridView widget, with a NULL value for "course_id" this way works: 'course.course_number', and this way generates the error "Trying to get property of non-object": array('name'=>'Course', 'value'=>'$data->course->course_number'), So I believe the best solution is to check for a NULL in the 'value' property (above). Unfortunately this level of
  9. Sorry to spam the list again. I just deleted all rows from the course_taken table, and it works now: array('name'=>'Course', 'value'=>'$data->course->department->department_abbreviation . " " . $data->course->course_number'), I did'nt even look at the data first, before deleting it, so it's not clear what the cause was. Onward! Larry Z.
  10. Hi there, I've got a column defined in a CGridView widget, in the view file admin.php, that correctly returns the course_number attribute from a related table: <?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'course-taken-grid', 'dataProvider'=>$model->search(), 'columns'=>array( 'course.course_number', // Other columns array( 'class'=>'CButtonColumn', ), ), )); ?> For some reason, if I use the name/value syntax to do the same thing: array('name'=>
  11. Oh, it turns out that the _view.php file is only used by the index.php file. Sorry if that mislead/confused anybody. Larry Z.
  12. For Pete's sake, I just figured it out, thanks to this post: http://www.yiiframework.com/forum/index.php/topic/28254-using-cdetailview-to-show-another-models-view/ and then this made more sense: http://www.yiiframework.com/doc/api/1.1/CDetailView#attributes-detail At least this is one way to do it I suppose. You can access data in the database directly using a relation defined in your model. In my Course model I have this relation: 'department' => array(self::BELONGS_TO, 'Department', 'department_id'), In the view.php file I add an attribute to the CDetailView w
  13. Hi, I'm using Yii version 1.1.13. I've generated a variable in a controller, that I need to display in the view file "_view.php". I pass the variable to "view.php" with render, and I can access it there. But I can't figure out how to access the variable from "_view.php", which uses the CDetailView widget. How is this done? Am I missing something? You would think this would be very easy, since it is such a common task. Thanks for any tips, Larry Z.
  14. Hi, I am having to use the same Model methods in several different views. For example, in several different views for creating a new record, I have forms that have a drop down list of years from which to choose. I can add the same method getYears() to each model, and call the method from _form.php, like so: <?php echo $form->dropDownList($model, 'year_entered', $model->getYears(), array('empty' => 'Select Year')); ?> Or, I can reuse that method from another view like so: <?php echo $form->dropDownList($model, 'year', OtherModel::getYears(), array('empty'
  • Create New...