ilikeme
(Eliyaoo12)
1
it’s my Lesson model:
<?php
class Lesson extends CActiveRecord
{
public static function model($class=__CLASS__)
{
return parent::model($class);
}
public function tableName()
{
return "lessons";
}
public static function create($title,$content)
{
$lesson = new Lesson;
$lesson->date = date("m.d.y");
$lesson->title = $title;
$lesson->content = $content;
$lesson->save();
}
}
?>
how can i get lesson by id?
like it:
SELECT * FROM `lessons` WHERE `id` = '1'
i hope you know what i mean:)
napeHeK
(Napehek)
2
$model = Lesson::model()->findByPk($id);
The model is better to write so
class Lesson extends CActiveRecord
{
public static function model($class=__CLASS__)
{
return parent::model($class);
}
public function tableName()
{
return "lessons";
}
public function beforeSave()
{
if(parent::beforeSave())
{
$this->date = date("m.d.y");
return false;
}
return false;
}
}
//later...
$lesson = new Lesson;
$lesson->title = '';
$lesson->content = '';
$lesson->save();
mdomba
(Maurizio Domba Cerin)
3
NOTE: moved to proper sub-forum (General Discussion instead of Tips, Snippets and Tutorials)
ilikeme
(Eliyaoo12)
4
and if i want to get by content or date?
tri
(tri - Tommy Riboe)
5
Read more about this in The Definitive Guide to Yii.
/Tommy