Catch stored procedure error

2009-07-21 Thread Simz

Hi,

i want to know if its possible to catch stored procedure error? i
would like to rollback on error...

$this-query('call sp_CustomersProduct_addProductsByFamily(?,?)',array
(1,1);
should i return a value on succes?

thank you

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problems with $uses and model relationships

2009-06-23 Thread Simz

Im not sure but try setting the kpi.id to something else than 0

On 23 juin, 10:06, DavidH djhollingwo...@gmail.com wrote:
 Hi Again

 I'm really getting stuck with my accessing the related data I need
 though my controller and into my view. To top it all I seem to have
 broken my controller by including a $uses statement to pull in the
 other models I want to access.

 Here's my model structure. Three models in the following relationship:

 Dashboard has many Kpi and a Kpi belongs to many dashboards
 A Kpi has many Ranges and a Range belongs to a Kpi
 A Range has one Colour and a Colour has many Ranges

 I'm pretty confident that all the relationships are set correctly in
 the models as I had a set of basic controllers / views working OK
 before.

 Now I've created a new 'showdashboard' method in my Dashboards
 controller along with a showdashboard.ctp view. The purpose of this is
 to display all the KPIs on a dashboard coloured according to which
 range the KPI value falls into.

 From my (still limited) understanding of Cake I had thought that by
 doing this:

 $this-Dashboard-recursive = 2;
 $dashboard = $this-Dashboard-find('first',
             array('conditions' = array('user_id' = $my_user,
 'default' = 1)));

 I would be able to access the entire hierachy from dashboard-range-

 colour however I couldn't get this to work. In the end I put in:

 var $uses = array('Dashboard', 'Range', 'Colour');

 at the top of the controller and this allowed me to do things like:

 $colours = $this-Colour-find('all');

 So my question is: should I have been able to get at the Range and
 Colour data without needing the $uses statement because these are
 related to the Dashboard? If this is the correct way of doing things
 could someone please post an example because I've totally got me head
 in a knot over this.

 Using $uses as above is only partially working in my showdashboards
 method. Even though the dashboard is being passed to the view, and
 this contains each of the 4 KPIs, the only KPI that has its Range data
 is the last one in the array.

 Here's my showdashboards method in full:

 function showdashboard()
     {
         //
         // Get the user ID from the session
         //
         $my_user = $this-Session-read('Auth.User.id');

         //
         // Read the default dashboard for this user
         //
         $this-Dashboard-recursive = 2;
         $dashboard = $this-Dashboard-find('first',
             array('conditions' = array('user_id' = $my_user,
 'default' = 1)));
         $kpi_ranges = $this-Range-find('all');
         debug($dashboard);

         //
         // Fetch all the colours back
         //
         $kpi_colours = $this-Colour-find('all');
         // debug($kpi_colours);

         //
         // Logic for deciding the staus of this KPI goes into the
 controller here
         //
         $kpi_index = 0;
         foreach ($dashboard['Kpi'] as $kpi)
         {
             $kpi_value = $kpi['kpi_value'];
             debug($kpi);
             //
             // Loop through all the levels testing where the current
 value
             // fits into the range.
             //
             $kpi_colour = ;
             foreach($kpi['Range'] as $level)
             {

                 debug($level);
                 if ($kpi_value = $level['low']  $kpi_value  $level
 ['high'])
                 {
                     $kpi_colour = $kpi_colours[$level['kpi_colour_id']]
 ['Colour']['hexcode'];
                 }
             }

             //
             // Check we found a valid level otherwise mark the KPI as
 out of range
             //
             if (strcmp($kpi_colour, ) == 0)
             {
                 $dashboard['Kpi'][$kpi_index]['kpi_value'] = 'Out Of
 Range';
                 $dashboard['Kpi'][$kpi_index]['kpi_colour'] =
 00;

             }
             else
             {
                 //
                 // Set the corect colour for the kpi on the dashboard
                 //
                 $dashboard['Kpi'][$kpi_index]['kpi_colour'] =
 $kpi_colour;
             }
             $kpi_index++;
         }

         //
         // Set up for the view
         //
         $this-set('dashboard', $dashboard);
     }

 This is the top of my $dashboards array from showdashboards.ctp. The
 Relative Humidity KPI should have 4 Ranges in this array. This is only
 working correctly for the last KPI in the array:

 Array
 (
     [Dashboard] = Array
         (
             [id] = 3
             [dashname] = David's Dashboard
             [user_id] = 4
             [default] = 1
         )

     [User] = Array
         (
             [id] = 4
             [password] = 8273c2212439e8fdfdf1db521b899d88638dff9c
             [userlevel_id] = 2
             [username] = David
             [Userlevel] = Array
                 (
                     [id] = 2
                     [levelname] = General Staff
                 )

             [Dashboard] = Array
                 (

Re: How to call validation in a form that doesn't use save()?

2009-02-06 Thread Simz

In your model use message inside your validation rules
http://book.cakephp.org/view/125/Data-Validation
by default a red message will be displayed under the invalid field.


you can access the error info from your controller using
$errors = $this-ModelName-invalidFields();
http://book.cakephp.org/view/410/Validating-Data-from-the-Controller


Use $this-set(errorvar,your custom error message); to display a
custom error message in your view

/* view */
echo $errorvar



On 6 fév, 14:27, libard...@gmail.com libard...@gmail.com wrote:
 Here's what I finally did, and it is working now:

   function search() {
     if (empty($this-data)) {
       // just render the view
     } else {
         $this-Book-set($this-data); // sends $data to the model for
 validation purposes.
         if ($this-Book-validates()) {
             $results = $this-Book-find('all',
                 array(
                     'conditions' = array(
                     'or' = array(
                         'Book.isbn' = $this-data['Book']['isbn'],
                         'Book.title' = $this-data['Book']['title'],
                         'Book.description' = $this-data['Book']
 ['description'],
                         'Book.author_name' = $this-data['Book']
 ['author_name'],
                         'Book.starred' = $this-data['Book']
 ['starred']
                         )
                     )
                 )
             );
         } else {
             $this-Session-setFlash('Your search contains wrong data,
 please check');
             $this-redirect(array('action' = 'search'));
         }

 Now, how would it be possible for me to provide the user with the
 validation feedback, such as showing in the view the messages upon
 validation failure?

 On Feb 5, 3:05 pm, libard...@gmail.com libard...@gmail.com wrote:

  Could you please provide a little more detail on how to do this?

  Specifically, what do you mean by just pass $this-data to be
  checked

  Sorry for the newbie question.

  On Jan 25, 1:28 pm, brian bally.z...@gmail.com wrote:

   You'll need to validate the user's input before you call find(). If
   you want, you can create methods in the model for that and just pass
   $this-data to be checked. Have the method(s) check the values and
   return true/false back to the controller.

   On Sun, Jan 25, 2009 at 7:31 AM, libard...@gmail.com

   libard...@gmail.com wrote:

I am learning Cake with a test project.

As far as I know, validation automatically occurs when the Model's save
() method is called from within a controller. So, if I have defined
validation rules in my model, those rules will be scrutinized before
actually either saving or editing data.

Now, what if the purpose of the form is not to save data?

Example. What if I create a form whose function is to perform a
search?

In this case, I am only using the $this-data information in
conjunction with the find() method, but I am not calling the save()
function.

So... my question, how could I link this search form with the
validation rules initially created for the add() and edit() actions
(which evidently make use of the save() function)?

Here is my sample code:

In my controller:
 function search() {
   if (empty($this-data)) {
     // just render the view
   } else {
     $results = $this-Book-find('all',
       array(
         'conditions' = array(
           'or' = array(
             'Book.isbn' = $this-data['Book']['isbn'],
             'Book.title' = $this-data['Book']['title'],
             'Book.description' = $this-data['Book']
['description'],
             'Book.author_name' = $this-data['Book']
['author_name'],
             'Book.starred' = $this-data['Book']['starred']
           )
         )
       )
     );
     $this-set('data', $this-data);
     $this-set('results', $results);
   }
 }

In my view (ctp file):

 ?php echo $form-create('Book', array('action'='search')); ?
 fieldset
 legend Search Books /legend
 ?php
   echo $form-input('isbn');
   echo $form-input('title');
   echo $form-input('description');
   echo $form-input('author_name');
   echo $form-input('starred');
 ?
 ?php echo $form-end('Search'); ?
 /fieldset

Thank you.
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Collecting data from array depending on Association

2009-02-06 Thread Simz

in case you don't find the good way ti do it i suggest you to
create a custom model method using $this-­query('your custom query')



On Feb 6, 7:57 pm, abergs.and...@gmail.com abergs.and...@gmail.com
wrote:
 Hello!

 Im been at this for hours and hanging in the IRC channel, without
 getting the final solution.
 I want to share events between users...

 **I have these relations:
 User hasmany Event
 Event HABTM User

 **I have these tables
 [events]
 -id
 -user_id
 -title

 [users]
 -id
 -email
 -and some other columns thats not interesting

 [events_users]
 -id
 -event_id
 -user_id
 -group_id (not used at the moment)

 When i perform
  $this-set('events', $this-Event-find('all'));

 I get this result:
 (this is $events)

 Array (
 [0] = Array ( [Event] = Array ( [id] = 9 [user_id] = 12 [title] =
 asdadg ) [User] = Array ( ) )
 [1] = Array ( [Event] = Array ( [id] = 12 [user_id] = 28 [title]
 = Clllmaann ) [User] = Array ( ) )
 [2] = Array ( [Event] = Array ( [id] = 23 [user_id] = 13 [title]
 = hehe, NOT SO FUNNY! )
         [User] = Array ( [0] = Array ( [id] = 12 [email] = aberg
 [password] = 5b1fb8132b0dee40ed8aec0e0049fb005f612e55 [fname] =
 [ename] = [status] = 0
         [EventsUser] = Array ( [id] = 1 [event_id] = 23 [user_id] = 12
 [group_id] = 0 ) ) ) )
 [3] = Array ( [Event] = Array ( [id] = 26 [user_id] = 12 [title]
 = OBOYOYOYOYOY12 ) [User] = Array ( ) ) ) 1

 -
 What i want to do with this array is that i want to collect those
 Events that has user_id = 12. Which normally is 'id':9 and 26. Though
 id 23 is shared to user_id 12. Therefore i want to collect it aswell!

 I dont know how to do this and have been searching for hours...

 Any help is greatly appreciated and i hope this can help others that
 have the same problem.
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Help with linked image swap

2009-02-06 Thread Simz

use the html helper : 
http://book.cakephp.org/view/206/Inserting-Well-Formatted-elements

image(string $path, array $htmlAttributes = array())

in your view (inside a php block)

echo $html-image(
menu1.jpg,
array(
onmouseover=­yourJsRollOverFunc(),
onclick=jsFunc(),
class=mycssclass
)
);

wrap the php block with your link...
this should do the trick

On Feb 6, 10:14 pm, Zolthar zolt...@gmail.com wrote:
 Learning cake/programming for the first time so please excuse me if
 this is a very noob question. I have tried to search this board
 without much success - as the responses were either too complicated or
 possibly I searching with the wrong keywords.

 What I am after is how do I get a linked image to swap like
 onmouseover using javascripts (or any other option)?
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: loading a layout from a database

2009-02-02 Thread Simz

Using elements?

On 2 fév, 15:14, Aurelius aurel...@temporaryinbox.com wrote:
 Hi!

 Whats the best way to read a layout from the database?

 Simply writing a model for the layout-table and using following layout-
 code?
 ?php
 echo $database_layout['top'];
 echo $scripts_for_layout;
 echo $database_layout['middle'];
 $session-flash();
 echo $content_for_layout; ?
 echo $database_layout['bottom'];
 echo $cakeDebug;
 ?

 Or is there an more elegant way?

 thx!
 Aurelius

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Call function in controller from model

2009-01-30 Thread Simz

Instead, you should return a status and call the debug functon from
controller
if ($this-Waitlist-save()) {
   ...
} else {
//debug here
}

btw parrent::errorlog while not call the controller... it will call
the model parent... (appmodel or model)


On 30 jan, 06:31, Henrik Gemal henrikge...@gmail.com wrote:
 In my model I want to call a debug function in the controller. But how
 do I do that?

 Something like:

 $ok = $waitlist-save($data);
 if (!$ok) {
         parent::errorlog(waitlist save not ok);

 or is this the wrong way to do thing? Should I use a completely
 different approche?

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---