Re: Image Upload, webroot path?
Yes that's exactly what I did wrong. Thank you very much! On 6 Nov., 18:19, cricket wrote: > On Sat, Nov 6, 2010 at 11:45 AM, Raphi wrote: > > Hi there, > > > I got a little issue loading up an image. > > > All the validation works just fine but when it comes to moving things > > around something happens to fail. > > I use this very simple code to move the uploaded temp file: > > > $filePath = WEBROOT_DIR . DS . 'product_img/'.$this->data['Product'] > > ['img']['name']; > > move_uploaded_file($this->data['Product']['img']['tmp_name'], > > $filePath); > > > I have a product_img folder within my webroot folder and its > > permissions are set to 777. However Cake throws the following errors: > > > Warning (2): move_uploaded_file(webroot/product_img/testbild2.jpg) > > [function.move-uploaded-file]: failed to open stream: No such file or > > directory [APP/controllers/products_controller.php, line 49] > > Code | Context > > > Warning (2): move_uploaded_file() [function.move-uploaded-file]: > > Unable to move '/is/htdocs/user_tmp/web44/phpqKQhWD' to 'webroot/ > > product_img/testbild2.jpg' [APP/controllers/products_controller.php, > > line 49] > > > I'm quite sure it's a problem with my filepath but I tried a lot and > > nothing worked here. I hope you guys will bail me out again. > > Look closer at the error msg. WEBROOT_DIR is just that--the name of > the webroot dir. You want to use WWW_ROOT. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Image Upload, webroot path?
Hi there, I got a little issue loading up an image. All the validation works just fine but when it comes to moving things around something happens to fail. I use this very simple code to move the uploaded temp file: $filePath = WEBROOT_DIR . DS . 'product_img/'.$this->data['Product'] ['img']['name']; move_uploaded_file($this->data['Product']['img']['tmp_name'], $filePath); I have a product_img folder within my webroot folder and its permissions are set to 777. However Cake throws the following errors: Warning (2): move_uploaded_file(webroot/product_img/testbild2.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory [APP/controllers/products_controller.php, line 49] Code | Context Warning (2): move_uploaded_file() [function.move-uploaded-file]: Unable to move '/is/htdocs/user_tmp/web44/phpqKQhWD' to 'webroot/ product_img/testbild2.jpg' [APP/controllers/products_controller.php, line 49] I'm quite sure it's a problem with my filepath but I tried a lot and nothing worked here. I hope you guys will bail me out again. Thanks in advance! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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: Problem with hasOne Relation
Ahh thank you guys so much! Adding the "url" to the form-helper did the trick. I'm using the Auth- component so I'll use $this->Auth->user('id') to identify the user. I also deleted the "belongsTo" statement from my user_profile model and everything is working in the exact same way so this really isn't necessary. It wasn't causing any problems but it's still good to know that you don't need it for a hasOne relation, so thanks for the info! thanks again and kind regards Raphi On 10 Okt., 08:38, and wrote: > Sometimes, if you use both 'hasOne' and 'belongsTo' it doesn't work. I > experienced it very often. Try just to use one of them. > And the second point is that, if you have typed it here correctly, > your $belongsTo is not correct. $belongsTo = array(''); but try it > without belongsTo. I had those issues also in my usermanagement where > I wanted to create a connection from the user itself to some special > properties like birthday and stuff like that. > > keep going :-) > > On 3 Okt., 20:01,Raphi wrote: > > > Hi there, > > > I'm new to Cake and now I seem to have a little understanding problem. > > The situation is this: > > > I have a UsersController and a User Model. Then there is an > > editProfile() method within my UsersController. Of course I also > > created a view (users/edit_profile.ctp). My problem is that I want to > > have an editable automagic form on that page that is linked to the > > user_profiles table. > > > What I did is, I added "var $hasOne = array('UserProfile');" to my > > User Model. And I created a form like this: > > > echo $form->create('UserProfile'); > > echo $form->input('id'); > > echo $form->input('name'); > > echo $form->end(); > > > Then I created a user_profile.php model file and added "var $belongsTo > > = 'User';" to it. The user_profiles table has a "user_id" foreign key. > > > When I send the form, cake throws an error as it cannot find the > > "UserProfileController". Normally this would be ok but for I want the > > UsersController to do all the work it's not. What can I do? I mean, I > > could create a user_profiles_controller.php to send the form and > > afterwards do a redirect to the form but that wouldn't be very > > fashionable. > > > I hope you can help me out. > > > Regards > > >Raphi Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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: Problem with hasOne Relation
Ok let me try to explain. I have two tables involved: users, user_profiles Of course there is a model-file to any of the tables so: user.php, user_profile.php The models are linked via a "hasOne"(parent key user_id) relationship. (which is working perfectly). But now I want to implement a method that gives users the possibility to alter their own profiles. Therefore I created an "editProfile" method in the UsersController and a corresponding view-file "edit_profile.ctp" in views/users. Within this view-file I created a form using the formhelper: echo $form->create('UserProfile'); echo $form->input('id'); echo $form->input('name'); echo $form->end('Save changes'); That is great because creating the form using "$form- >create('UserProfile');" makes it automatically fill in the values from the database. My problem occurs when it comes to submitting the form. Cake recognizes the "UserProfile" model and tries to use the "UserProfileController" which does not exist. I want to use the UsersController to do that job. I mean I know I could use "$form- >create('User');" in order to get it working but that makes it impossible for cake to fill out the form automatically. I don't really get why using the "User" model doesn't work. For there is an existing relationship the "User" model should be able to pass on the user_profiles datas. On 4 Okt., 20:16, cricket wrote: > On Sun, Oct 3, 2010 at 4:49 PM, Raphi wrote: > > Hi, thank you for you quick response. Unfortunately I neither do use > > AJAX nor have the data saved in the users table. I guess I have to use > > two controllers anyway. :( > > Well, perhaps you could state your problem clearer, then. What is the > schema of the tables you are using? And explain what this means: > > > My problem is that I want to > > have an editable automagic form on that page that is linked to the > > user_profiles table. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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: Problem with hasOne Relation
Hi that doesn't work. Cake takes the array and outputs it as html attributes to the form tag: echo $form->create('UserProfile',array('controller' => 'users', 'action' => 'editUser')); gives me: '') array the controller seems to be predefined by conventions. So a create('UserProfile') form will always require a users_profile_controller. (?) On 4 Okt., 06:03, Hank wrote: > echo $form->create('UserProfile'); > > to > > echo $form->create('UserProfile',array('controller' => 'users', > 'action' => 'editUser')); > > On Oct 3, 11:01 am, Raphi wrote: > > > Hi there, > > > I'm new to Cake and now I seem to have a little understanding problem. > > The situation is this: > > > I have a UsersController and a User Model. Then there is an > > editProfile() method within my UsersController. Of course I also > > created a view (users/edit_profile.ctp). My problem is that I want to > > have an editable automagic form on that page that is linked to the > > user_profiles table. > > > What I did is, I added "var $hasOne = array('UserProfile');" to my > > User Model. And I created a form like this: > > > echo $form->create('UserProfile'); > > echo $form->input('id'); > > echo $form->input('name'); > > echo $form->end(); > > > Then I created a user_profile.php model file and added "var $belongsTo > > = 'User';" to it. The user_profiles table has a "user_id" foreign key. > > > When I send the form, cake throws an error as it cannot find the > > "UserProfileController". Normally this would be ok but for I want the > > UsersController to do all the work it's not. What can I do? I mean, I > > could create a user_profiles_controller.php to send the form and > > afterwards do a redirect to the form but that wouldn't be very > > fashionable. > > > I hope you can help me out. > > > Regards > > > Raphi Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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: Problem with hasOne Relation
Hi, thank you for you quick response. Unfortunately I neither do use AJAX nor have the data saved in the users table. I guess I have to use two controllers anyway. :( On 3 Okt., 22:36, cricket wrote: > On Sun, Oct 3, 2010 at 2:01 PM, Raphi wrote: > > Hi there, > > > I'm new to Cake and now I seem to have a little understanding problem. > > The situation is this: > > > I have a UsersController and a User Model. Then there is an > > editProfile() method within my UsersController. Of course I also > > created a view (users/edit_profile.ctp). My problem is that I want to > > have an editable automagic form on that page that is linked to the > > user_profiles table. > > > What I did is, I added "var $hasOne = array('UserProfile');" to my > > User Model. And I created a form like this: > > > echo $form->create('UserProfile'); > > echo $form->input('id'); > > echo $form->input('name'); > > echo $form->end(); > > > Then I created a user_profile.php model file and added "var $belongsTo > > = 'User';" to it. The user_profiles table has a "user_id" foreign key. > > > When I send the form, cake throws an error as it cannot find the > > "UserProfileController". Normally this would be ok but for I want the > > UsersController to do all the work it's not. What can I do? I mean, I > > could create a user_profiles_controller.php to send the form and > > afterwards do a redirect to the form but that wouldn't be very > > fashionable. > > Assuming that the data you want to modify are in the users table, and > that you want to submit the form with AJAX, you can handle it all with > a single action in UsersController. > > AppController: > > public $components = array('Auth', 'Session', 'RequestHandler', ...); > > function beforeFilter() > { > parent::beforeFilter(); > > // ... > > if ($this->RequestHandler->isAjax()) > { > Configure::write('debug', 0); > $this->layout = 'ajax'; > } > > } > > UsersController: > > function beforeFilter() > { > parent::beforeFilter(); > > // ... > > if ($this->RequestHandler->isAjax()) > { > $this->viewPath = 'elements/users'; > } > > } > > public function edit() > { > $id = $this->Auth->user('id'); > > if (!$id) > { > $this->flash('invalid request'); > } > > if (!empty($this->data)) > { > if ($this->User->save($this->data)) > { > if ($this->RequestHandler->isAjax()) > { > $this->render('profile'); > } > } > else > { > if ($this->RequestHandler->isAjax()) > { > $this->render('form'); > } > } > } > else > { > $this->data = $this->User->read(null, $id); > } > > // set whatever else you need > > } > > views/elements/users/form.ctp: > > if (!empty($form->validationErrors)) > { > ?> > There was an error in the submission. Please review > the fields below. > > ?> > * Required Field > > switch ($this->params['action']) > { > case 'admin_add': > > echo $form->create('User', array('action' => 'add', 'admin' > => 1)); > break; > > case 'add': > > echo $form->create('User', array('action' => 'add')); > break; > > case 'admin_edit': > > echo $form->create('User', array('action' => 'edit', 'admin' > => 1)); > echo $form->hidden('User.id'); > break; > > case 'edit': > > echo $form->create('User', array('action' => 'edit')); > echo $form->hidden('User.id'); > break; > > } > > In the case blocks above, you could include your JS link(s) for the > AJAX form stuff. You can also switch on $this->params['action'] for > the submit buttons, test it for whether to include certain fields, > etc. The add, edit, admin_add, admin_edit views all just include the > form element. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Problem with hasOne Relation
Hi there, I'm new to Cake and now I seem to have a little understanding problem. The situation is this: I have a UsersController and a User Model. Then there is an editProfile() method within my UsersController. Of course I also created a view (users/edit_profile.ctp). My problem is that I want to have an editable automagic form on that page that is linked to the user_profiles table. What I did is, I added "var $hasOne = array('UserProfile');" to my User Model. And I created a form like this: echo $form->create('UserProfile'); echo $form->input('id'); echo $form->input('name'); echo $form->end(); Then I created a user_profile.php model file and added "var $belongsTo = 'User';" to it. The user_profiles table has a "user_id" foreign key. When I send the form, cake throws an error as it cannot find the "UserProfileController". Normally this would be ok but for I want the UsersController to do all the work it's not. What can I do? I mean, I could create a user_profiles_controller.php to send the form and afterwards do a redirect to the form but that wouldn't be very fashionable. I hope you can help me out. Regards Raphi Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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