Tuesday, November 30, 2010

Re: dynamically changing the type in form helper

Hi,

Are you sure that $type1 is a string?

Amit Badkas

PHP Applications for E-Biz: http://www.sanisoft.com



On Wed, Dec 1, 2010 at 7:39 AM, mochaman <mochamanbj@gmail.com> wrote:
Hi,

I want to override the input 'type' in my form using the form helper
but it is not picking up my values.  Here is a snippet:

echo $form->input($name,array('type'=>$type1,'label'=>$label));

I set $name, $type1, and $label as a strings read in from my config
xml file, however, I get the following error upon rendering the page:

Fatal error:  Method name must be a string in form.php on line 878

It appears to be an issue with $type1 since if I replace it with
'text' (ie, hardcoded), then it works but everything is a text box
rather than date or checkbox.  I have also tried putting quotes in the
data but no luck...everything just defaults to textarea.

I am a newbie to php and cake so I know it is probably something
simple...

Any assistance is appreciated.
Thanks.

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

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

Re: dynamically changing the type in form helper

What is the value of $type1 when you get the error?
Which version of CakePHP are you using?
What are the values of the other variables when you get the error?
Enjoy,
John

On 1 Dec., 03:09, mochaman <mochama...@gmail.com> wrote:
> Hi,
>
> I want to override the input 'type' in my form using the form helper
> but it is not picking up my values.  Here is a snippet:
>
> echo $form->input($name,array('type'=>$type1,'label'=>$label));
>
> I set $name, $type1, and $label as a strings read in from my config
> xml file, however, I get the following error upon rendering the page:
>
> Fatal error:  Method name must be a string in form.php on line 878
>
> It appears to be an issue with $type1 since if I replace it with
> 'text' (ie, hardcoded), then it works but everything is a text box
> rather than date or checkbox.  I have also tried putting quotes in the
> data but no luck...everything just defaults to textarea.
>
> I am a newbie to php and cake so I know it is probably something
> simple...
>
> Any assistance is appreciated.
> Thanks.

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

Re: Form validation and routes - errors lead to controller/action instead of route!

Hey,


ok I found the solution, and it's really simple. Just use the 'url'
option for the form, and the routes will be no problem anymore.

Here is a brief example how to do it:

In Routes-PHP, there is an entry:
Router::connect('/register', array('controller' => 'users', 'action'
=> 'register'));

And the form in the view of the register action (views/users/
register.ctp) create the form like this:

<?php echo $form->create('User', array('url' => '/register')); ?>

That points the form to the correct route, which will lead to the
correct action. On errors like empty input fields the route will be
the same again and everthing works fine.

Regards,

DD

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

Form validation and routes - errors lead to controller/action instead of route!

Hey,


the problem I have came up very often the last weeks but I couldn't
find a solution yet. Maybe one of you has a clue how to do this.

The facts:

in my users_controller i have an action called "register", which is
mapped to the route http:://www.domain.com/register

This is working, and very easy to set up. But when I now make any
mistake in the form given in the register action, the url in the
browser switches back to users/register, which is the correct action,
but not the correct route!

I could do a redirect when an error occurs, but the form validation
errors (by model validation OR invalidate()) are gone when a redirect
is done.

There has to be a solution for this, I just do not want to store all
errors in the Session and add the errors manually into the form and
delete them afterwards from the Session.

Does anyone have any idea how to solve this little problem?

Regards,

DD

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

Missing Method??

I m trying to make a controller and a view without model. Here are the code:
Controller:
<?php
class BooksController extends AppController {
var $name = 'Books';
var $uses = array();

function index($id = 0) {
$books = array (
'0' => array(
'book_title' => 'OOP with PHP5',
'author' => 'Hasin Hayder',
'isbn' => '1847192564',
'release_date' => 'December 2007'
),
'1' => array(
'book_title' => 'Building website with Joomla',
'author' => 'Hagen Grraf',
'isbn' => '1847192577',
'release_date' => 'March 2006'
)
);
$id = intval($id);
if($id < 0 || $id >= count($books)) {
$id = 0;
}
$this->set($books[$id]);
$this->set('page_heading', 'Book Store');
$this->pageTitle = 'Welcome to the Packt Book Store!';
}
}

View:

<h2><?php echo $page_heading; ?></h2>
<dl>
<lh><?php echo $book_title; ?></lh>
<dt>Author:</dt><dd><?php echo $author; ?></dd>
<dt>ISBN:</dt><dd><?php echo $isbn; ?></dd>
<dt>Release Date:</dt><dd><?php echo $releaseDate; ?></dd>
</dl>

Those are example from CakePHP Application Development, but
unfortunately the book was using Cake 1.2.x while I have 1.3.6
version. If I try to open it via
http://http://localhost/applogic/books/ looks OK, but if I try
http://http://localhost/applogic/books/1 an error occur like:

Missing Method in BooksController
Error: The action 1 is not defined in controller BooksController

Error: Create BooksController::1() in file:
app/controllers/books_controller.php.

<?php
class BooksController extends AppController {

var $name = 'Books';


function 1() {

}

}
?>

Something not compatible between those 2 version?

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

Re: Error : VALID_NOT_EMPTY

nope, maybe i should. thx for the helpful links guys.

On Tue, Nov 30, 2010 at 4:24 PM, Amit Badkas <amit.sanisoft@gmail.com> wrote:
> Hi,
> Aren't you following http://book.cakephp.org/view/1528/Blog for creating
> sample blog application?
> Amit Badkas
> PHP Applications for E-Biz: http://www.sanisoft.com
>
>
> On Tue, Nov 30, 2010 at 9:03 AM, Hans Wiriya Tsai <hansw.id@gmail.com>
> wrote:
>>
>> great, thx for the prompt help! I would of course read the entire docs
>> (later), but your quick help is very helpful for a beginner like me.
>>
>> On Tue, Nov 30, 2010 at 9:23 AM, cricket <zijn.digital@gmail.com> wrote:
>> > On Mon, Nov 29, 2010 at 5:43 AM, Hans Wiriya Tsai <hansw.id@gmail.com>
>> > wrote:
>> >> I hv CakePHP 1.3.6 installed on Ubuntu and learning to create simple
>> >> blog. When I add validation to my model, I got this error:
>> >>
>> >> Notice (8): Use of undefined constant VALID_NOT_EMPTY - assumed
>> >> 'VALID_NOT_EMPTY' [CORE/cake/libs/class_registry.php, line 141]
>> >>
>> >>
>> >> Here's my model:
>> >> <?php
>> >> class Blog extends AppModel {
>> >>        var $name = 'Blog';
>> >>        var $validate = array(
>> >>                        'title' => array(
>> >>                                        'rule' => VALID_NOT_EMPTY,
>> >>                                        'message' => 'Title of a blog
>> >> cannot be empty'
>> >>                        )
>> >>        );
>> >> }
>> >> ?>
>> >>
>> >> Any idea what this error is all about? Thx for any help.
>> >
>> > Yes, it's an undefined constant. VALID_NOT_EMPTY was deprecated awhile
>> > back. Use 'rule' => 'notEmpty' instead.
>> >
>> > http://book.cakephp.org/view/1143/Data-Validation
>> >
>> > 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+unsubscribe@googlegroups.com For more options, visit this group
>> > at http://groups.google.com/group/cake-php?hl=en
>> >
>>
>> 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+unsubscribe@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php?hl=en
>
> 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+unsubscribe@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

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

dynamically changing the type in form helper

Hi,

I want to override the input 'type' in my form using the form helper
but it is not picking up my values. Here is a snippet:

echo $form->input($name,array('type'=>$type1,'label'=>$label));

I set $name, $type1, and $label as a strings read in from my config
xml file, however, I get the following error upon rendering the page:

Fatal error: Method name must be a string in form.php on line 878

It appears to be an issue with $type1 since if I replace it with
'text' (ie, hardcoded), then it works but everything is a text box
rather than date or checkbox. I have also tried putting quotes in the
data but no luck...everything just defaults to textarea.

I am a newbie to php and cake so I know it is probably something
simple...

Any assistance is appreciated.
Thanks.

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