I’m currently learning Yii and trying to create a time tracking application where users can track their working time spent on different projects.
I now managed to change the default application so that users and project data are managed in a MySQL database.
What I would like to create is some kind of “dashboard” page that is shown when a user logs on where he can see all the projects assigned to him in one table but also a list of tracked entries… but I’m not sure how to start.
Is there any sample on how to show data from various databse tables (of course as results of specific queries)?
The second thing I’m looking for is how to create data entry forms that have drop-down fields which are filled with data from a table (e.g. a list of projects that are available to the currently logged on user)
Despite the really good documentation, the learning curve is still quite steep for me…
Ah ok - but that is not what I’m after (maybe I might use this later sometimes…)
Imagine a "edit time entry" form where a use can change his personal time records… one of the form elements would be a dropdown that contains all possible projects with the specific project selected that was used to create this time entry.
So most of the forms controls come from the "times" table.
The possible selections of the dropdown comes from the "projects" table and the number/id of the currently selected project would come from the "times" table.
In the sample you show, the dropdown items are in a literal array, but I need them to be filled by the result of a query (since not all projetcs are allowed for every user)
One of my problems is that I’m not only new to Yii… but also relatively new to PHP…
The best way to start is to get a good understanding of CActiveRecord. If your tables are already created, use ‘gii’ to generate your models and to generate CRUD operations. Looking at the generated code will certainly inspire you a lot.
If your mysql db is not with an engine allowing foreign keys, finish your model generation manually by adding ‘HAS_MANY’ and ‘BELONGS_TO’ relations (and a few rules like ‘exist’…)
I am just throwing few ideas for you to start spinning the wheels (from my understanding of what you’re after).
Do it step by step, start easy. Start by being able to generate a form for saving/updating a single entry, then by being able to list available time records for your current user. And then more complex…
Generating a form is easy with CActiveForm widget => look at what CRUD can do for you and then adjust. You may want to use CHtml::listData() for your dropdown list.
For grabbing all the times for the current user. Considering ‘Time’ and ‘Project’ are your models with a time record belonging to a User and a Project.
But I don’t understand why this is not the correct way.
I also have a problem with CActiveDataProvider and SQL joins.
The following query works without problems in EMS SQLManager:
select tbl_user.username, tbl_projects.projectname, tbl_times.start_time, tbl_times.stop_time
where tbl_times.id_user = `tbl_user`.id and `tbl_times`.id_project = tbl_projects.id and isnull(tbl_times.stop_time)
But I’m lost on how to do this with the CActiveDataProvider… I always get ‘unknown column in where clause’…
The biggest problem I see with the API documentation is that there are no comprehensive code samples for the methods and attributes… so the beginner has to jump around in circles, searching forum, sample codes, tutorials etc. - thank god for tabbed browsers