Converting an existing project to Yii (part 2)

Hi, all,

I’m in the midst of converting an existing project to Yii. The existing project is an app for viewing, searching, sorting, etc. a large collection of documents organized into categories, subjects, and groups. These basic features seem fairly easy to duplicate in Yii.

However, one of the ancillary features in the OP was a “previously viewed documents” list. The OP would keep a list of the last documents the user viewed, which would always be accessible from a sidebar in one of the columns. I’m wondering if people have thoughts about how to implement this feature in Yii, or even if there is a better way to implement it than the one originally devised.

The difficulty I am seeing is how to keep the running list of previously viewed documents available even after loading a new view (like going from the index to viewing a specific document.) I can see a few ways of accomplishing the task, in broad detail, but each has potential problems.

In the OP, the previously viewed documents feature worked as follows: the sidebar column and the main column were both filled out via Ajax request. This meant that the page as a whole was never reloaded. When the user clicked a document from the main column of the index page (which had a list of documents taken from the database), this ran a bit of javascript which: (a) updated the previously viewed documents list in the sidebar, and ( b ) did an ajax request to replace the content of the main column with a view of the particular document the user clicked on.

This method kind of worked, but there were some problems. One problem was making sure the url in the browser window changed to reflect what the user was doing. Another problem was that the whole thing depended on the user having javascript enabled: without javascript, the user would not be able to view any documents at all (obviously, not every feature has to work with javascript disabled, but the basic ones should still work.)

There are ways around both of these problems. One can use links with "onclick" events that return false in the document list, and a jquery plugin can be leveraged to update the url in the browser.

But is this ajax solution really the best solution as a whole? And, more importantly, is there a better, more Yii-centric solution available? I was thinking that maybe the previously viewed documents (their ids, or whatever) could be stored in the hash fragment of the url somehow. Does anyone have thoughts on that?

And don’t worry, I’m not looking for anyone to hold my hand and do it for me. But a little inspiration would be nice :-).

This is just my 2 cents. You could store the info in the session if it only needs to be kept per session. Otherwise, you’re in the database. You create a widget to display this info as part of your layout. The widget would read the info from the session or the database as required. To update the info, you pass a docid as part of your url. The controller takes the docid, updates the session/database for recently viewed, and then displays the correct document by rendering a view. The details of course depend on where your documents are stored, but this general approach should work without javascript. The downside is that every document refresh is a full page load. You might be able to cheat a little by using frames so that the header doesn’t refresh.

Ha, I didn’t even think of using session vars. That would save a heck of a lot of trouble vs. trying to do things through the hash part of the url. Thanks for the heads up.

Per session will probably be okay, although the database solution you outline is intriguing. Thanks again.

Terrence

I got an issue,jquery loading multiple times.If any body have any solution then please let me know

localhost/projects/test/development/assets/82701a3f/jquery.js

localhost/projects/test/development/assets/82701a3f/jquery.js?_=1383631940296

So great,

Where is the part1?