Re: Where Does This Fall in the MVC Architecture?

2008-12-09 Thread Dave C

Tony,

One approach you could use:

As suggested by Jon Bennett:
* create a method in the model to fetch the data
* create an action in the controller to request the data in the model

Then:
* create a JSON or XML view for the action
* create a JavaScript control for your display that will
asynchronously request and display the data.

Since you want it on every page, you can put the control in your
layout.

I've taken this approach and it works nicely. It may not be an issue
for your case, but it's especially good for queries that aren't really
fast.

Dave.

On Dec 9, 9:35 am, Tony Thomas <[EMAIL PROTECTED]> wrote:
> I'm working on an application to store information on lab specimens.
> The lab receive specimens which are divided into aliquots which are
> then put into boxes and in turn stored in freezers.
>
> I want to create a function to find all unstored aliquots and display
> a message on every page to alert the lab users that there are aliquots
> that haven't been assigned to boxes yet. It's a simple query:
>
> SELECT COUNT(aliquot.id)
> FROM aliquots
> WHERE aliquots.box_id IS NULL
>
> The problem is that I can't quite decide where it belongs in the MVC
> architecture. It seems like a helper since the alert message would
> appear in the left column of every page. But it runs a query, so does
> it belong in a model? The problem is that I want to retrieve the
> information no matter which model is currently in use.
>
> What's the best way to preserve the MCV structure and DRY philosophy
> while including a function like this in my application?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: CakePHP Unit Test Model Woes :(

2008-11-28 Thread Dave C

Stop me if you've heard this before, but I'm having a problem unit
testing models. I've followed this conversation and poked around a
bunch elsewhere. Progress, but not yet a solution.

Problem: When I run my test case, CakePHP successfully inserts my
fixture data in to "user_tests" (and associated tables). But when it
runs the query, it selects from "users". This is using CakePHP 1.2
RC3.

The output shows me that it is working with the test_suite database
connection. I'm starting the test database with the tables defined,
but empty. After calling ClassRegistery::init(), $this->User->table is
'users', as is $this->User->useTable. I'd expected to see 'user_tests'
for it to work, but no dice.

Can anybody tell me what I'm doing wrong?

Thanks,

Dave C.

// condensed model (leaving out an association and other methods
class User extends AppModel {
function validateLogin($data) {
$params = array('conditions' => array('username' => $data
['username'],
  'passwd' =>sha1($data
['passwd'])),
'recursive' => 2,
'fields' => array('id', 'username'));
$user = $this->find('all', $params);
...
}
}

// my fixture:
class UserTestFixture extends CakeTestFixture {
var $name = 'UserTest';

public $import = 'User';

public $records = array(
array('id' => 1, 'name' => 'Test User1', 'username' =>
'test1',
  'email' => '[EMAIL PROTECTED]', 'parentuser_id' => null)
);
}

// my test:
class UserTestCase extends CakeTestCase {
public $fixtures = array('app.user_test');

public function testValidateLogin() {
$this->User =& ClassRegistry::init('User');

$validUser = array('username' => 'test1', 'passwd' => null);
$this->assertTrue($this->User->validateLogin($validUser),
  'User was not found, but should have been:
%s');
}
}

On Nov 26, 12:57 pm, pragna <[EMAIL PROTECTED]> wrote:
> Mark:
> Yeah, but the fixture file I've posted was created using the
> 'fixturize' script from the guys at 
> debuggable:http://debuggable.com/posts/fixturize-shell---generate-your-fixtures-...
>
> It reads from an existing table (in the default db) and also reads
> records in that table to build a fixture which contains $records but,
> as you've pointed out, does not include an import statement for a
> table or model. I think this is probably intentional but I haven't
> been able to get the Debuggable example working.
>
> This is what I mean about everyone seems to be building their unit
> tests slightly differently.
> Andy
>
[snip]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---